Python 2.7 on Windows, “assert main_name not in sys.modules, main_name” for all multiprocessing examples

匿名 (未验证) 提交于 2019-12-03 01:08:02

问题:

There is following simple code:

from multiprocessing import Process, freeze_support  def foo():     print 'hello'  if __name__ == '__main__':     freeze_support()     p = Process(target=foo)     p.start() 

It works good on Linux or Windows with Python 3.3, but fails on Windows with Python 2.7.

Traceback (most recent call last):   File "", line 1, in    File "c:\Python27\lib\multiprocessing\forking.py", line 346, in main     prepare(preparation_data)   File "c:\Python27\lib\multiprocessing\forking.py", line 454, in prepare     assert main_name not in sys.modules, main_name AssertionError: thread 

Generally speaking, all multiprocessing examples i tried fail on that setup. Why?

回答1:

This is a known bug:

http://bugs.python.org/issue10845

Not sure if this will ever get ported to 2.7.X.



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