“NoneType”对象没有属性“\u registry”-Python多处理
我正在使用Python多处理进程Manager dict。我想运行以下脚本:“NoneType”对象没有属性“\u registry”-Python多处理,python,multiprocessing,Python,Multiprocessing,我正在使用Python多处理进程Manager dict。我想运行以下脚本: from time import sleep from multiprocessing import Process from multiprocessing import Queue, Value, Array from multiprocessing import Manager def main(id_, graf_dict): print('Граф {} готов'.format(id_))
from time import sleep
from multiprocessing import Process
from multiprocessing import Queue, Value, Array
from multiprocessing import Manager
def main(id_, graf_dict):
print('Граф {} готов'.format(id_))
graf_dict[id_] = 1
if id_ == '3':
graf_dict[id_] = 0
print(graf_dict)
while True:
check = 0
for key in graf_dict:
if graf_dict[key] == 0:
check = 1
break
if check == 0:
print('Все графы авторизованы')
break
if __name__ == "__main__":
manager = Manager()
graf_control = manager.dict()
graf_control['1'] = 0
graf_control['2'] = 0
graf_control['3'] = 0
print(graf_control)
p1 = Process(target=main, args=(str(1), graf_control,))
p2 = Process(target=main, args=(str(2),graf_control,))
p3 = Process(target=main, args=(str(3),graf_control,))
p1.start()
sleep(1)
p2.start()
sleep(1)
p3.start()
p1.join()
p2.join()
p3.join()
但我有一个错误:
AttributeError: 'NoneType' object has no attribute '_registry'
我没有找到这个错误的解决方案,我需要帮助来运行代码。有什么方法可以做到这一点吗?请提供完整的堆栈跟踪。使用graf_dict.keys在子进程中迭代管理器dict。@Darkonaut我认为你是对的。此外,代码的逻辑似乎是错误的。特别是,当_id=3时,无限循环运行,graf_dict['3']设置为0。因为您正在检查graf_dict中的任何值是否等于0,所以循环将永远运行,直到您中断它为止。