问题描述
我有问题.
i在Windows7(64位)上使用python(2.7.7,32位)和py2exe(0.6.9).
i using python(2.7.7, 32bit) and py2exe(0.6.9) on Windows7(64bit).
我的应用程序结构如下:
my application structure such as the following:
from multiprocessing import Process
def child():
print "child"
def main():
print "main"
p = Process(target=child)
p.start()
p.join()
if __name__ == "__main__":
main()
(1)打包前的结果:
main
child
(2)打包后的结果:
main
main
main
...(forever)
我想在包装后得到(1).
i want to get (1) after packaging.
请告诉我包装后如何获得(1).
please tell me how to get (1) after packaging.
爱.
推荐答案
如注释中所述,将Python脚本打包到Windows可执行文件中时,需要调用multiprocessing.freeze_support()
.此调用应在if __name__ == '__main__':
之后,然后才实际调用main()
.
As mentioned in the comments, you need a call to multiprocessing.freeze_support()
when packaging a Python script into an executable for use on Windows. This call should come just after if __name__ == '__main__':
before actually calling main()
.
这篇关于python multiprocessing.Process执行错误的目标(与py2exe打包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!