uwsgi +flask 部署中,uwsgi的配置文件中的自动重载代码配置项无法生效


uwsgi的配置文件如下:

   
  <uwsgi>
  
<pythonpath>/var/ngu</pythonpath>
<module>run</module>
<enable-threads/>
<callable>app</callable>
<socket>:9001</socket>
<py-autoreload>1</py-autoreload>
<plugins>python</plugins>
<processes>4</processes>
<harakiri>20</harakiri>
<harakiri-verbose/>
<memory-report/>
<daemonize>/var/ngu/log.txt</daemonize>
</uwsgi>

由于通过uwsgi自动重载代码配置无法生效,我就尝试先不用uwsgi启,直接python run.py的方式启动项目,flask框架开启debug模式后,当有代码更新时,自己会进行重载,但当更新代码时,日志中会打出以下内容

   
  Traceback (most recent call last):
  
File "run.py", line 12, in <module>
app.run(host="0.0.0.0")
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 708, in run_simple
run_with_reloader(inner, extra_files, reloader_interval)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 617, in run_with_reloader
sys.exit(restart_with_reloader())
SystemExit: 0

可能uwsgi自动重载代码配置失效跟这个有关,我追进去看了下源码,可能是当有代码更新时,watcher创建新进程失败。。有人知道这个是什么原因吗?弄了几天了。。

flask uwsgi

魔法兔斯基 10 years, 6 months ago

Your Answer