Flask auto-reload and long-running thread

久未见 提交于 2019-12-10 16:13: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:


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.



来源:https://stackoverflow.com/questions/9672871/flask-auto-reload-and-long-running-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!