I'm using Python multiprocessing Process, Manager (dict). I want to run this script:
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()
But I got an error:
AttributeError: 'NoneType' object has no attribute '_registry'
I didn't find a solution to this error and I need help to get the code running. Are there any ways to do this?
graf_dict.keys()for iterating over the manager-dict in a child process._id = 3, the infinite loop is run,graf_dict['3']is set to0. Because you are checking for whether any values ingraf_dictare equal to0, the loop will run forever until you break it.