为什么multiprocessing.Pool在python中给出了如此奇怪的错误?

时间:2014-10-02 12:34:04

标签: python python-2.7 multiprocessing

请提出建议,该怎么做。无法理解发生了什么。我想在python中使用multiprocessing.Pool运行简单的测试脚本。

我在windows上运行,python 2.7

当我开始我的脚本时,我看到错误,永远不会结束。我无法得到正在发生的事情。我复制了我的大名单的一部分:

    prepare(preparation_data)
  File "C:\Python27\lib\multiprocessing\forking.py", line 488, in prepare
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
    assert main_name not in sys.modules, main_name
AssertionError: thread
prepare(preparation_data)
  File "C:\Python27\lib\multiprocessing\forking.py", line 488, in prepare
      File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
    Traceback (most recent call last):
  File "<string>", line 1, in <module>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
assert main_name not in sys.modules, main_name
    assert main_name not in sys.modules, main_name
Traceback (most recent call last):
        AssertionErrorprepare(preparation_data)
AssertionError  File "<string>", line 1, in <module>
prepare(preparation_data)
  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
:   File "C:\Python27\lib\multiprocessing\forking.py", line 488, in prepare
: prepare(preparation_data)
  File "C:\Python27\lib\multiprocessing\forking.py", line 488, in prepare
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
t  File "C:\Python27\lib\multiprocessing\forking.py", line 488, in prepare
    t            hreadprepare(preparation_data)
hreadassert main_name not in sys.modules, main_name
prepare(preparation_data)
assert main_name not in sys.modules, main_name

  File "C:\Python27\lib\multiprocessing\forking.py", line 488, in prepare

AssertionError  File "C:\Python27\lib\multiprocessing\forking.py", line 488, in
prepare
AssertionError        :     : assert main_name not in sys.modules, main_name
assert main_name not in sys.modules, main_name
tassert main_name not in sys.modules, main_name
tAssertionErrorAssertionErrorhreadAssertionErrorhread: :
:
tttTraceback (most recent call last):
  File "<string>", line 1, in <module>
hreadhreadhread  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in
 main

......等等......

我的小代码:

from multiprocessing import Pool

def display(item):
    print 'item: ' + str(item)


def main():
    items = []
    for i in range(0, 999):
        items.append(i)

    pool = Pool(10)
    pool.map(display, items)
    pool.close()
    pool.join()

if __name__ == '__main__':
    main()

0 个答案:

没有答案