这与此问题基本相同:这个问题,但那里给出的解决方案(调用freeze_support())对我不起作用。
我有一个名为start.py的脚本,我使用它来使用py2exe(版本0.9.2.2)构建独立可执行文件。我还在同一目录中拥有python.exe。
这显然是因为调用了某个函数。
如果我不调用set_executable()和freeze_support(),子进程将仅启动exe并作为__main__运行,导致无限的新进程打印“Parent”,而“Child”从未被打印。唯一调用freeze_support()所做的事情似乎是导致子进程引发以下错误,如果我不调用multiprocessing.set_executable():
我正在使用运行在Windows 8.1 64位上的Python 3.4 32位。我已经尝试了所有使用cx-Freeze的方法,但都没有获得相同的结果。如果有帮助,将不胜感激。 编辑:即使使用这个直接从文档中复制的示例:
我有一个名为start.py的脚本,我使用它来使用py2exe(版本0.9.2.2)构建独立可执行文件。我还在同一目录中拥有python.exe。
import multiprocessing
def main():
print('Parent')
p = multiprocessing.Process(target=new_process)
multiprocessing.set_executable('python.exe')
p.start()
p.join()
def new_process():
print('Child')
if __name__ == '__main__':
multiprocessing.freeze_support()
main()
在纯 Python 环境下运行时,一切正常。但是,当打包为可执行文件时,会出现以下错误:
Unknown option: --
usage: <path to start.exe> [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
这显然是因为调用了某个函数。
python.exe --multiprocessing-fork
如果我不调用set_executable()和freeze_support(),子进程将仅启动exe并作为__main__运行,导致无限的新进程打印“Parent”,而“Child”从未被打印。唯一调用freeze_support()所做的事情似乎是导致子进程引发以下错误,如果我不调用multiprocessing.set_executable():
Traceback (most recent call last):
File "start.py", line 17, in <module>
multiprocessing.freeze_support()
File "C:\Python34\Lib\multiprocessing\context.py", line 148, in freeze_support
freeze_support()
File "C:\Python34\Lib\multiprocessing\spawn.py", line 67, in freeze_support
main()
NameError: name 'main' is not defined
我正在使用运行在Windows 8.1 64位上的Python 3.4 32位。我已经尝试了所有使用cx-Freeze的方法,但都没有获得相同的结果。如果有帮助,将不胜感激。 编辑:即使使用这个直接从文档中复制的示例:
from multiprocessing import Process, freeze_support
def f():
print('hello world!')
if __name__ == '__main__':
freeze_support()
Process(target=f).start()
当子进程调用freeze_support()函数时,我会收到相同的NameError错误。