python 多进程报错

python 多进程报错

    for (room_name,room_id) in json_data.items():
        if room_id!='0':
            print(room_name+":"+room_id)
            if room_name=="SecooShanghai":
                p1 = multiprocessing.Process(target=douyin_webcast.excute_main, args=(room_name,room_id,))
                p1.start()
                p1.join()
            if room_name=="dyxbhjks5p73":
                p2 = multiprocessing.Process(target=douyin_webcast.excute_main, args=(room_name,room_id,))
                p2.start()
                p2.join()
            if room_name=="Secoobeijing":
                p3 = multiprocessing.Process(target=douyin_webcast.excute_main, args=(room_name,room_id,))
                p3.start()
                p3.join()
            if room_name=="DYSECOO":
                p4 = multiprocessing.Process(target=douyin_webcast.excute_main, args=(room_name,room_id,))
                p4.start()
                p4.join()

报错日志

Traceback (most recent call last):
  File "E:/pythonproject/douyinlive - 副本 (2)/msg_test.py", line 260, in 
    p1.start()
  File "D:\loading\python3.8\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "D:\loading\python3.8\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "D:\loading\python3.8\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "D:\loading\python3.8\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
    reduction.dump(process_obj, to_child)
  File "D:\loading\python3.8\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle : it's not the same object as __main__.douyin_webcast

最佳答案

变量传递出错 进程间对象共用不了 target传进去也不是同一个对象了 要用线程才是同一个对象