我有这个使用多处理的简单地图示例。但即使这样我也无法正确运行。
import multiprocessing
p = multiprocessing.Pool()
rere = range(50)
print p.map(lambda x: x+1, rere)
它将打印此异常:
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
并且无法使用 Ctrl+C 终止。
我应该如何修复我的示例以使其正常工作?