Flask auto-reload and long-running thread

2019-06-23 22:40发布

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.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-23 23:24

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.

查看更多
登录 后发表回答