中可能缺少测试。
以下代码在python 3.6.1 ...但在python 3.6.5中返回此错误:
Traceback (most recent call last):
File "G:/GOOD/Coding/Deepthroat/Deepthroat2/Bin/Testing/gh.py", line 36, in <module>
loops.start()
File "C:Program FilesPython36libmultiprocessingprocess.py", line 105, in start
self._popen = self._Popen(self)
File "C:Program FilesPython36libmultiprocessingcontext.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:Program FilesPython36libmultiprocessingcontext.py", line 322, in _Popen
return Popen(process_obj)
File "C:Program FilesPython36libmultiprocessingpopen_spawn_win32.py", line 65, in __init__
reduction.dump(process_obj, to_child)
File "C:Program FilesPython36libmultiprocessingreduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <function loops at 0x0000019D3E30B598>: it's not the same object as __main__.loops
这是代码:
from multiprocessing import Process
import time
def timeout(mm):
for i in range(6):
time.sleep(0.1)
print('stop all bla loops now')
mm.terminate()
return
def loops():
for i in range(5):
time.sleep(0.1)
print('loop1')
billy = 'loop1 done'
for i in range(5):
time.sleep(0.1)
print('loop2')
billy = 'loop2 done'
for i in range(5):
time.sleep(0.1)
print('loop3')
billy = 'loop3 done'
billy = 'cool'
loops = Process(target=loops)
loops.start()
timeout = Process(target=timeout(loops))
timeout.start()
这实际上只是您的错误,因为您正在覆盖loops
,这意味着它不能被腌制(Pickle只是存储对该功能的引用(。如果您说此错误在python3.6.1中没有发生,那么python3.6.1
如果目标和变量都具有与 loops = Process(target=loops)
相同的名称,则此错误返回。
我可以在上述答案中使用Medalng的解释和Rhys的评论来解决我的问题。再次重申它以帮助他人,因为我可以在第三次访问中观看Rhys的评论。