问题
When i tried to run the following code:
from pathos.multiprocessing import ProcessingPool as Pool
list1 = [1,2,3,4,5]
list2 = [6,7,8,9,10]
def function1(x,y):
print x
print y
if __name__ == '__main__':
pool = Pool(5)
pool.map(function1, list1, list2)
It gets the followwing error:
Traceback (most recent call last):
File "test.py", line 9, in <module>
pool.map(function1, list1, list2)
File "C:\Python27\lib\site-packages\pathos\multiprocessing.py", line 136, in map
return _pool.map(star(f), zip(*args)) # chunksize
File "C:\Python27\lib\site-packages\multiprocess\pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "C:\Python27\lib\site-packages\multiprocess\pool.py", line 567, in get
raise self._value
cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
Isn't pathos.multiprocessing is designed to solve this problem?
回答1:
I'm the pathos
author. When I try your code, I don't get an error. However, if you are seeing a CPickle.PicklingError
, I'm guessing you have an issue with your install of multiprocess
. You are on windows, so do you have a C compiler? You need one for multiprocess
to get a full install of multiprocess
.
来源:https://stackoverflow.com/questions/44094924/pathos-multiprocessing-pool-cpickle-error