cx_freeze multiprocessing 打包后反复重启

写了给flask程序,此外还需要用multiprocessing 启动一个守护进程。

不打包一切正常,用cx_freeze打包后,发现flask反复重启。任务管理器里这个GUI窗口的进程数不断增加。

经过一番Google,发现python 官方给出了办法啊! NB啊

https://docs.python.org/3/library/multiprocessing.html#multiprocessing.freeze_support

Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable. (Has been tested with py2exePyInstaller and cx_Freeze.)

 

One needs to call this function straight after the if __name__ == '__main__' line of the main module. For example:

 

 

需要在flask app所在启动的 app.py的 中增加一句

...
from multiprocessing import freeze_support
...

if __name__ == '__main__':
    freeze_support()
    ...
    app.run(host='0.0.0.0')

 

Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable. (Has been tested with py2exePyInstaller and cx_Freeze.)

One needs to call this function straight after the if __name__ == '__main__' line of the main module. For example:

 

 
posted @ 2019-12-01 09:33  永远的幻想  阅读(651)  评论(0编辑  收藏  举报