python multiprocessing.Process executes a wrong target (packaged with py2exe)

二次信任 提交于 2019-12-10 22:20:19

问题


i have a problem.

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)result before packaged:

main
child

(2)result after packaged:

main
main
main
...(forever)

i want to get (1) after packaging.

please tell me how to get (1) after packaging.

love.


回答1:


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().

Link to multiprocessing.freeze docs



来源:https://stackoverflow.com/questions/26001133/python-multiprocessing-process-executes-a-wrong-target-packaged-with-py2exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!