Python 3.6.5中的多处理PicklingError在3.6.1中没有出现

时间:2018-04-28 17:17:31

标签: python python-3.x process multiprocessing

以下代码适用于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 Files\Python36\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Program Files\Python36\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Program Files\Python36\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Program Files\Python36\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Program Files\Python36\lib\multiprocessing\reduction.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()

1 个答案:

答案 0 :(得分:0)

这实际上只是一个错误,因为你覆盖loops,这意味着它不能被腌制(pickle只存储对该函数的引用)。如果你说这个错误没有在python3.6.1中发生,那么python3.6.1中可能缺少测试