对于所有多处理示例,Windows上的Python 2.7“断言main_name不在sys.modules,main_name”

有以下简单的代码:
from multiprocessing import Process,freeze_support

def foo():
    print 'hello'

if __name__ == '__main__':
    freeze_support()
    p = Process(target=foo)
    p.start()

它在使用Python 3.3的Linux或Windows上运行良好,但在使用Python 2.7的Windows上运行失败.

Traceback (most recent call last):
  File "<string>",line 1,in <module>
  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

一般来说,我试过的所有多处理示例都失败了.为什么?

这是一个已知的错误:

http://bugs.python.org/issue10845

不确定这是否会被移植到2.7.X.

相关文章

windows无法连接到wifi怎么办
文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...