No, the book warns to avoid that approach: 
http://www.web2py.com/books/default/chapter/29/04/the-core#Accessing-the-API-from-Python-modules

You cannot assign the thread local object to a top-level variable in the 
module, as it will only be assigned once upon first import.

Anthony

On Sunday, December 14, 2014 7:32:29 PM UTC-5, Mark Graves wrote:
>
> Hey everyone,
>
> I could use a sanity check here from the community.
>
> In a controller I get a record, then, I want to pass do some database 
> calls from a module.
>
> It seems that the least code I could write would be in models:
>
> from gluon import current
> current.db = db
>
> Then in the module at the top
>
> from gluon import current
> db = current.db
>
> The method I was using was passing the objects in directly to the function 
> defined in the module, but that was overly repetitive.  No classes, just 
> functions.
>
> Can anyone see where I would run into problems? Is this thread safe?
>
> Would it be better to instantiate a class with the handler similar to what 
> I've seen elsewhere regarding model-less apps?
>
> Thanks in advance!
>
> -Mark
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to