Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask auto-reload and long-running thread

I'm implementing a long-running thread within a Flask application. In debug mode, with the reloader activated, the long-running thread is not killed upon reload.

Instead, because the code that creates and starts the thread is run after reloading, each cycle creates an additional thread.

How can I prevent this, other than disabling the reloader?

Will the same happen when running under mod_wsgi, with its auto-reload feature?

Update: the long-running thread was actually killed by Werkzeug upon reloading. There is an extra copy, which is due to Werkzeug's reloader taking an extra thread which runs the initialization code.

like image 974
jd. Avatar asked Oct 08 '22 10:10

jd.


1 Answers

The mod_wsgi reloading is described in:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

In the case of a long running request, by default if it doesn't complete within 5 seconds the process will be forcibly killed anyway. This is to avoid problem of process locking up because a request will not finish.

like image 129
Graham Dumpleton Avatar answered Oct 11 '22 00:10

Graham Dumpleton