Windows 上的 Python 2.7,所有多处理示例的 "assert main_name not in sys.modules, main_name"

标签 python windows python-2.7 multiprocessing program-entry-point

简单的代码如下:

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 上的 Python 2.7,所有多处理示例的 "assert main_name not in sys.modules, main_name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16405687/

相关文章:

python - 检查 python 列表中的重复项

Python:如何将 pickled txt 文件转换为用于networkx的gpickles?

java - 如何启动 Web 服务器并在完成后将浏览器指向它?

python - python 中的负零

c - 调用函数时元素消失 - LZW 压缩

c++ - 提升 :asio IPv4 address and UDP comms

python-2.7 - 从 Google Cloud Storage 存储分区进行 pip 安装

python - FieldStorage 输入删除了一些字符

python - Numpy 将标量转换为数组

python - 检查线程是否已在 MicroPython 中启动