I have a class that contains a (large) number of different properties, including a few dictionaries. When I pass an instance of the class through to a new process, all of the numeric values seem to get passed in correctly, but any dictionaries that were in the class object get emptied.
Here’s a simple test I cooked up that demonstrates my problem:
from multiprocessing import Process
class State:
a = 0
b = {}
def f(s, i):
print "f:", s.a, s.b
def main():
state = State()
state.a = 11
state.b['testing'] = 12
print "Main:", state.a, state.b
ps = []
for i in range(1):
p = Process(target=f, args=(state, i))
p.start() # Do the work
ps.append(p)
for p in ps:
p.join()
if __name__ == '__main__':
main()
I expect the output to be
Main: 11 {'testing': 12}
f: 11 {'testing': 12}
but instead I get
Main: 11 {'testing': 12}
f: 11 {}
I ended up working around this problem by passing the dictionaries in explicitly in addition to the state. e.g.
p = Process(target=f, args=(state, i, state.b))