多进程报错
Traceback (most recent call last):File "C:\Users\miaochangbin\PycharmProjects\eduCrawler\main.py", line 138, in <module>p.start()File "D:\Program Files\python\lib\multiprocessing\process.py", line 121, in startself._popen = self._Popen(self)File "D:\Program Files\python\lib\multiprocessing\context.py", line 224, in _Popenreturn _default_context.get_context().Process._Popen(process_obj)File "D:\Program Files\python\lib\multiprocessing\context.py", line 327, in _Popenreturn Popen(process_obj)File "D:\Program Files\python\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__reduction.dump(process_obj, to_child)File "D:\Program Files\python\lib\multiprocessing\reduction.py", line 60, in dumpForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle '_thread.lock' object
原因
- 在启动子进程时,会将所有输入参数经过信息序列化后传递到子进程中,而报错就是在信息进行序列化时候。
- 而这边信息报错传递子进程的对象信息(属性以及属性的属性)。
- 因此:说明代码中有类或者对象无法被序列化,但是被传入子进程中,去除对应无法实例化的代码,或者将其放在子进程中初始化即可。
参考文章:
- 多进程 报错 TypeError: cannot pickle ‘_thread.lock‘ object