Threads in app

53 views
Skip to first unread message

Dmitrii Ermolaev

unread,
Dec 12, 2020, 6:20:46 AM12/12/20
to web2py-users
code:
threadGetRate = Thread(target=get_from_exch, args=(db, exchg))
threadGetRate.start()

I start app by:

> web2py.py -S 7pay_in -M -R applications/7pay_in/modules/serv_rates.py -A True 60

rise error - for connection to DB

Dave S

unread,
Jan 30, 2021, 12:58:50 AM1/30/21
to web2py-users
I'm not sure what you are trying to do here, and I don't what error you are saying is happening.

Can you provide more information?

(typically, each request runs in its own thread, and how many threads there are may depend on the front end (Rocket, NginX, Apache, unicorn, etc);  The scheduler also managers a pool of threads).)

/dps


 

valq...@gmail.com

unread,
Jan 30, 2021, 2:16:07 PM1/30/21
to web2py-users
It is because pydal-db-connection is thread safe and as you switch to another thread there is no initialized pydal-db-connection in that thread
so you can try db._adapter.reconnect() in your target function (this is that py4web does on every request)
And (as far as I understand) you cannot share uncommitted db-changes between threads as they each have their own db connection
суббота, 30 января 2021 г. в 08:58:50 UTC+3, snide...@gmail.com:
Reply all
Reply to author
Forward
0 new messages