python TypeError: can't pickle _thread.RLock objects

在写多进程类的时候遇到了这么个问题

Traceback (most recent call last):
  File "C:/Users/wei.wu/Desktop/trade/monitor/kp.py", line 93, in 
    kp.start()
  File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\ProgramData\Anaconda3\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\ProgramData\Anaconda3\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\ProgramData\Anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\ProgramData\Anaconda3\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle _thread.RLock objects

bugs.python.org上给出的答案是这不是一个bug

后来进过检查发现继承了进程类的类在初始化时,pickle模块要对内部的成员变量进行序列化,但不支持对自定义对象加锁,所以会抛出类型异常的错误。我在类构造时使用了又初始化了外部的日志对象,将这部分代码注释掉后,问题便解决了,最终重写日志模块

你可能感兴趣的:(python)