Python: Using a multidimensional multiprocessing.manager.list() -


this might not intended use, know how use multidimensional manager.list(). can create on fine, this:

from multiprocessing import manager  test = manager.list(manager.list()) 

however when ever try access first element of test list returns element's value , not proxy object

test[0]  # returns [] , not proxy, since think python running __getitem__. 

is there anyway me around , use manager.list() in way?

the multiprocessing documentation has note on this:

note

modifications mutable values or items in dict , list proxies not propagated through manager, because proxy has no way of knowing when values or items modified. modify such item, can re-assign modified object container proxy:

# create list proxy , append mutable object (a dictionary)  lproxy = manager.list()  lproxy.append({}) # mutate dictionary  d = lproxy[0] d['a'] = 1  d['b'] = 2 # @ point, changes d not yet synced, # reassigning dictionary, proxy notified of change  lproxy[0] = d 

so, way use multidimensional list reassign changes make second dimension of list top-level list, instead of:

test[0][0] = 1 

you do:

tmp = test[0] tmp[0] = 1 test[0] = tmp 

not pleasant way things, can write helper functions make bit more tolerable.

edit:

it seems reason plain list when append listproxy listproxy because of how pickling proxies works. baseproxy.__reduce__ creates rebuildproxy object, used unpickle proxy. rebuildproxy looks this:

def rebuildproxy(func, token, serializer, kwds):     '''     function used unpickling proxy objects.      if possible shared object returned, or otherwise proxy it.     '''     server = getattr(process.current_process(), '_manager_server', none)      if server , server.address == token.address:         return server.id_to_obj[token.id][0]     else:         incref = (             kwds.pop('incref', true) ,             not getattr(process.current_process(), '_inheriting', false)             )         return func(token, serializer, incref=incref, **kwds) 

as docstring says, if unpickling occuring inside manager server, actual shared object created, rather proxy it. bug, , there 1 filed against behavior already.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -