How to access db in a new thread ?

28 views
Skip to first unread message

Marc Legendre

unread,
Nov 28, 2019, 4:07:56 PM11/28/19
to web2py-users
Hello,

I would like to access to the db variable declared in db.py in another thread but I get this error:

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

Despite a lot of research, I can't find a way to make it work. Does anyone has an idea of how to counter this problem ?

Massimo Di Pierro

unread,
Nov 28, 2019, 6:20:41 PM11/28/19
to web2py-users
No you cannot and you should not. In web2py you have one thread per http request. You should not spawn other threads because you either slow down responses or you may leak memory.
This is not web2py specific. This is true for all web applications.

What is your ultimate goal? There is probably a proper way to do what you need.
Reply all
Reply to author
Forward
0 new messages