首页 > 其他 > 详细

cx_freeze multiprocessing 打包后反复重启

时间:2019-12-01 11:51:03      阅读:85      评论:0      收藏:0      [点我收藏+]

写了给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:

 

 

cx_freeze multiprocessing 打包后反复重启

原文:https://www.cnblogs.com/xuanmanstein/p/11965145.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!