Flask自动重装和长时间运行的线程 [英] Flask auto-reload and long-running thread

查看:282
本文介绍了Flask自动重装和长时间运行的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Flask应用程序中实现一个长时间运行的线程。在调试模式下,在激活重载程序的情况下,长重线程在重载时不会被终止。



相反,因为创建和启动线程的代码是在重新加载后运行的,所以每个循环都会创建一个额外的线程。



在mod_wsgi下运行时,同样会发生同样的情况,它有自动重载功能吗?



更新:长时间运行的线程实际上在重新加载后被Werkzeug杀死。有一个额外的副本,这是由于Werkzeug的重载程序采取额外的线程运行初始化代码。

解决方案

mod_wsgi重新加载描述如下:

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



在长时间运行请求的情况下,默认情况下,如果在5秒内没有完成,过程将被强行终止。这是为了避免过程锁定问题,因为请求不会完成。


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.

解决方案

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.

这篇关于Flask自动重装和长时间运行的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆