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

 

 

相关文章:

  • 2021-12-21
  • 2021-05-20
  • 2022-12-23
  • 2021-06-07
  • 2021-09-14
  • 2022-02-13
  • 2021-06-03
猜你喜欢
  • 2021-09-05
  • 2022-12-23
  • 2021-04-07
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案