执行示例
from multiprocessing import Process
def f(name):
print 'hello', name
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
从包的 python 文档中multiprocessing
得到一个PicklingError: Can't pickle <function f at 0x05A57830>: it's not found as __main__.f
.
我该如何解决这个问题?
完整的错误信息是
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py", line 128, in runfile
execfile(filename, glbs)
File "C:\Users\Ruben\Desktop\untitled0.py", line 15, in <module>
p.start()
File "C:\Python27\lib\site-packages\multiprocessing-2.6.2.1-py2.7-win32.egg\multiprocessing\process.py", line 109, in start
self._popen = Popen(self)
File "C:\Python27\lib\site-packages\multiprocessing-2.6.2.1-py2.7-win32.egg\multiprocessing\forking.py", line 244, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python27\lib\site-packages\multiprocessing-2.6.2.1-py2.7-win32.egg\multiprocessing\forking.py", line 167, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
PicklingError: Can't pickle <function f at 0x05A57830>: it's not found as __main__.f