cx_freeze multiprocessing 打包后反复重启
Posted xuanmanstein
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 py2exe, PyInstaller 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 py2exe, PyInstaller 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 打包后反复重启的主要内容,如果未能解决你的问题,请参考以下文章
Python cx_Freeze 错误“没有名为 'cx_Freeze.util' 的模块”
cx_freeze 错误“cx_Freeze.freezer.ConfigError:没有名为控制台的基础”
使用 cx_freeze 后不会出现 QGraphicsPixmapItem