I have a separate process that I run along with my web application by 
creating a subprocess like so:

           subprocess.Popen("python web2py.py -v -e -a admin -i 0.0.0.0 -p 
8080 -c <cert_file> -k <key_file>".split())
subprocess.Popen("python web2py.py -S <app_name> -M -R <path_to_process>
".split())

In that process, I start a thread to do some tasks. I have assigned the 
callbacks from that thread to the callbacks in that process:

Class Process:

    def __init__(self):
        self.thread = MyThread() #MyThread is a threading.Thread object
        self.thread.callback = self.callback
        self.thread.start()

    def self.callback(self, event):
        print db(auth_user.id=1).first_name

In the self.callback, when I try to read from the database using the db 
object I get the following error:

AttributeError: 'thread._local' object has no attribute 
'_pydal_connection_55197392_9964'

I have tried making the db object a member of the Process class and then 
trying to access it in the callback:

Class Process:

    def __init__(self):
        self.db = db
        self.thread = Threading.thread()
        self.thread.callback = self.callback
        self.thread.start()

    def self.callback(self, event):
        print self.db(auth_user.id=1).first_name

I still get the same error.

How can I access the database from inside a thread created inside a process 
running in a shell?

-- 
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