Pathos(python模块)在IDE和shell中表现不同

时间:2017-07-07 21:47:23

标签: python multiprocessing pycharm pathos

我试图了解如何使用Pathos包来运行调用函数的函数。根据我的理解,Pathos优于主要多处理包的优点是它允许函数内部的函数。但是,我似乎无法使其发挥作用。这是我能提出的最简单的例子:

def testf(x):
    print(x)

import dill
import pathos
from pathos.multiprocessing import ProcessingPool
pool = ProcessingPool(nodes=3)
out2 = pool.map(testf, [1,2,3,4,5,6,7,8,9])
pool.close()

输出:

multiprocess.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/james/.local/lib/python3.6/site-packages/multiprocess/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/home/james/.local/lib/python3.6/site-packages/multiprocess/pool.py", line 44, in mapstar
    return list(map(*args))
  File "/home/james/.local/lib/python3.6/site-packages/pathos/helpers/mp_helper.py", line 14, in <lambda>
    func = lambda args: f(*args)
  File "<input>", line 2, in testf
NameError: name 'print' is not defined
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "<input>", line 5, in <module>
  File "/home/james/.local/lib/python3.6/site-packages/pathos/multiprocessing.py", line 136, in map
    return _pool.map(star(f), zip(*args)) # chunksize
  File "/home/james/.local/lib/python3.6/site-packages/multiprocess/pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/home/james/.local/lib/python3.6/site-packages/multiprocess/pool.py", line 608, in get
raise self._value
NameError: name 'print' is not defined

编辑:似乎如果我将此代码粘贴到shell控制台中,它可以正常工作。如果我从我选择的IDE,PyCharm运行它,就没有骰子。所以现在我的问题是为什么相同的代码在同一版本的python解释器(3.6.1)中的工作方式不同,基于它是从shell运行还是在应用程序内控制台/

0 个答案:

没有答案