This is because you are accessing the variable at the index of the list a second time, while the first time you are passing a valid variable. As stated in multiprocessor docs :
Modifications of the changed values ββor elements in the dict and list proxy files will not be transmitted through the dispatcher, since the proxy server does not know when its values ββor elements will be changed.
This means that to track items that have been changed in the container (dictionary or list), you must reassign them after each edit. Consider the following change (for explanatory purposes, I do not claim that this is pure code):
def editDict(d, l, i): d[1] = 10 d[2] = 20 d[3] = 30 l[i] = d mlist = m.list([m.dict() for i in xrange(pnum)]) for i in xrange(pnum): p = Process(target=editDict,args=(mlist[i], mlist, i,)) p.start()
If you type mlist
now, you will see that it has the same result as your first attempt. Reassignment will allow the container proxy to track the updated item again.
Your main problem in this case is that you have a dict
(proxy) inside the list
proxy: updates to the contained container will not be noticed by the manager and, therefore, will not have the expected changes. Please note that the dictionary itself will be updated in the second example, but you just do not see it, because the manager did not synchronize.
jro
source share