I have multiprocessor code in which I would like to share a nested dictionary among processes. A dictionary is never modified by processes; just read it.
In its simplest form, the problematic code is as follows:
from multiprocessing import Manager
class MyClass(object):
def __init__(self):
self.manager = Manager()
self.delays = self.manager.dict({})
def foo(self, types, keys):
for type in types:
self.delays[type] = self.manager.dict({})
for key in keys:
self.delays[type][key] = 0
print("The delay is " + str(self.delays[type][key]))
I get KeyError
a print statement that says that the key I'm using does not exist. I am not sure why this is happening since I just inserted the key in the dict. When I change this to a regular dict, the problem disappears.
source
share