Windows上的Python 2.7,“声明main_name不在sys.modules中,main_name".对于所有多处理示例 [英] Python 2.7 on Windows, "assert main_name not in sys.modules, main_name" for all multiprocessing examples

查看:155
本文介绍了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()

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

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 "<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

通常来说,我尝试过的所有多处理示例在该设置上均失败.为什么?

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

推荐答案

这是一个已知的错误:

http://bugs.python.org/issue10845

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

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

这篇关于Windows上的Python 2.7,“声明main_name不在sys.modules中,main_name".对于所有多处理示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆