python - multiprocessing map raises exception -
this question has answer here:
- python multiprocessing pickling error 7 answers
i have simple example of map using multiprocessing. can't make run correctly.
import multiprocessing p = multiprocessing.pool() rere = range(50) print p.map(lambda x: x+1, rere)
it print exception:
exception in thread thread-3: traceback (most recent call last): file "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner self.run() file "/usr/lib/python2.7/threading.py", line 761, in run self.__target(*self.__args, **self.__kwargs) file "/usr/lib/python2.7/multiprocessing/pool.py", line 342, in _handle_tasks put(task) picklingerror: can't pickle <type 'function'>: attribute lookup __builtin__.function failed
and unable terminate ctrl+c.
how should fix example make work?
ok research strange world of multiprocessing...
the way trying it, not enough. heres how managed pull off.
import multiprocessing mp import time def thegenerator(): number in xrange(10): yield number def processnumber(x): return x*2 def multiprocessthings(): pool = mp.pool() gen = thegenerator() result = pool.map(processnumber, gen) print result if __name__ == "__main__": multiprocessthings() time.sleep(10)
save wherever, , double click on it.
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
also apparently type of stuff not work in interpreter reason.
Comments
Post a Comment