“NoneType”对象没有属性“\u registry”Python多处理

2024-06-17 09:00:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是Python多处理进程管理器(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_))
    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'

我没有找到这个错误的解决方案,我需要帮助来运行代码。有没有办法做到这一点


Tags: fromimportidtargetifmainchecksleep