首页 > 编程语言 > 详细

pyinstaller打包多线程代码,运行死循环?

时间:2021-01-03 10:39:35      阅读:136      评论:0      收藏:0      [点我收藏+]

描述现象

用pyinstaller打包了一个上传文件的脚本,里面有多个input在while循环内,然后启用了多线程上传,在编辑器中运行没问题,但是打包完后,就一直循环提示你input...

解决

在google了一段时间后,发现需要在执行入口之前调用

multiprocessing.freeze_support()      # here

然后程序的运行就正常了。

python官网解释

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:

from multiprocessing import Process, freeze_support
def f():
    print(‘hello world!‘)

if __name__ == ‘__main__‘:
    freeze_support()
    Process(target=f).start()
If the freeze_support() line is omitted then trying to run the frozen executable will raise RuntimeError.

Calling freeze_support() has no effect when invoked on any operating system other than Windows. In addition, if the module is being run normally by the Python interpreter on Windows (the program has not been frozen), then freeze_support() has no effect.

pyinstaller打包多线程代码,运行死循环?

原文:https://www.cnblogs.com/cpl9412290130/p/14224550.html

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