Skip to content Skip to sidebar Skip to footer

Keyerror When Attempting To Access A Key Value From A Nested Manager.dict

I have some multiprocessing code where I'd like to share a nested dictionary among processes. The dictionary is never modified by the processes; just read. In the simplest form, th

Solution 1:

Based on this answer to a related question, you can use a Manager.list appending a dict, then use a reference to the dict:

from multiprocessing import Manager
class MyClass(object):

    def __init__(self):
        self.manager = Manager()
        self.l = self.manager.list()
        self.l.append({})
        self.delays = self.l[0]

    def foo(self, types, keys):
        for type in types:
            self.delays[type] = self.manager.dict()
            for key in keys:
                self.delays[type].setdefault(key, 0)
                print("The delay is {}".format(self.delays[type][key]))

Post a Comment for "Keyerror When Attempting To Access A Key Value From A Nested Manager.dict"