这个问题的后续问题 悲情多处理不能腌制
将代码合二为一:
from pathos.multiprocessing import ProcessingPool as Pool
def f(x):
return x*x
if __name__ == '__main__':
p = Pool(5)
print(p.map(f, [1,2,3]))
Traceback (most recent call last):
File "\femto.niddk.nih.govCAll ProjectsNMR High PressureSoftwaremultiprocessingmultiprocessing_playground_2.py", line 12, in <module>
results = ProcessingPool().map(b.boo, [[12,3,456],[8,9,10],['a','b','cde']])
File "C:Python27libsite-packagespathosmultiprocessing.py", line 137, in map
return _pool.map(star(f), zip(*args)) # chunksize
File "C:Python27libsite-packagesmultiprocesspool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "C:Python27libsite-packagesmultiprocesspool.py", line 567, in get
raise self._value
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
>>>
以下是更多信息:
>>> pathos.__version__
'0.2.2.dev0'
>>> import multiprocess
>>> multiprocess.__version__
'0.70.5'
>>> import multiprocessing
>>> multiprocessing.__version__
'0.70a1'
>>> multiprocess.Pool().map(lambda x:x*x, range(10))
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
multiprocess.Pool().map(lambda x:x*x, range(10))
File "C:Python27libsite-packagesmultiprocesspool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "C:Python27libsite-packagesmultiprocesspool.py", line 567, in get
raise self._value
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
这是怎么回事?为什么不工作?Pathos图书馆不是应该使用莳萝而不是腌制吗?
如果我使用
from pathos.pools import ParallelPool as Pool
而不是
from pathos.multiprocessing import ProcessingPool as Pool
之
from pathos.pools import ProcessPool as Pool
谁能解释有什么区别?所有这些方法都会创建不同的过程。