[英]Error when running a .exe file using Python multiprocessing
I recently dabbled with multiprocessing
in one of my python projects.我最近在我的 python 项目之一中涉足了
multiprocessing
。
I would run my script in my terminal and everything would run flawlessly.我会在我的终端中运行我的脚本,一切都会完美运行。 However, when I turned the
.py
script into a .exe
using pyinstaller
it wouldn't work anymore.但是,当我使用
pyinstaller
将.py
脚本转换为.exe
时,它不再起作用了。
I've narrowed it down to the issue being the Manager()
method.我已将其缩小到
Manager()
方法的问题。
Consider the following piece of code:考虑以下代码:
from multiprocessing import Manager
if __name__ == '__main__':
print("Starting")
manager = Manager()
print("Worked")
Running the script as a .py
file outputs:将脚本作为
.py
文件运行输出:
> Starting
> Worked
After converting to a .exe
the script outputs Starting
continuously:转换为
.exe
后,脚本输出连续Starting
:
> Starting
> Starting
> Starting
etc...
I managed to snatch this error code after performing a keyboardinterrupt on the running code if any help.如果有任何帮助,我在对正在运行的代码执行键盘中断后设法抓住了这个错误代码。
Please let me know if you guys encounter the same issue, or have any idea how to fix this.如果你们遇到同样的问题,或者知道如何解决这个问题,请告诉我。 Have a great weekend <3
周末愉快<3
Thank you so much gddc all I had to do was非常感谢gddc我所要做的就是
import an extra method导入额外的方法
and add an extra command并添加一个额外的命令
The code now looks like this:代码现在看起来像这样:
from multiprocessing import Manager, freeze_support
if __name__ == '__main__':
freeze_support()
print("Starting")
manager = Manager()
print("Worked")
<kite.com/python/docs/multiprocessing.freeze_support> <kite.com/python/docs/multiprocessing.freeze_support>
The thing is...pyinstaller has a lot of problems.问题是...pyinstaller 有很多问题。 In fact, most modules for converting
.py
files to .exe
do.事实上,大多数用于将
.py
文件转换为.exe
的模块都可以。 To be honest, I don't really think it's a problem with multiprocessing, but it might be.老实说,我真的不认为这是多处理的问题,但它可能是。 I suggest maybe trying other modules to convert
.py
to .exe
, like cx_freeze
or auto_py_to_exe
我建议也许尝试其他模块将
.py
转换为.exe
,例如cx_freeze
或auto_py_to_exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.