''NoneType' object has no attribute '_registry' - Python multiprocessing
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?
Solution 1:[1]
As per @Darkonaut comment, use graf_dict.keys() like so:
...
for key in graf_dict.keys():
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | trex |
