remote multiprocessing, shared object

Kushal Kumaran kushal.kumaran+python at gmail.com
Thu Apr 8 02:20:51 EDT 2010


On Thu, Apr 8, 2010 at 11:30 AM, Norm Matloff <matloff at doe.com> wrote:
> Thanks very much, Kushal.
>
> But it seems to me that it doesn't quite work.  After your first client
> below creates l and calls append() on it, it would seem that one could
> not then assign to it, e.g. do
>
>   l[1] = 8
>
> What I'd like is to write remote multiprocessing code just like threads
> code (or for that matter, just like shared-memory multiprocessing code),
> i.e. reading and writing shared globals.  Is this even possible?
>

Try this server:
from multiprocessing.managers import BaseManager, ListProxy
shared_list = []
class ListManager(BaseManager): pass
ListManager.register('get_list', callable=lambda:shared_list,
proxytype=ListProxy)
m = ListManager(address=('', 50000), authkey='abracadabra')
s = m.get_server()
s.serve_forever()

Just changed the proxy type appropriately.  See the managers.py file
in the multiprocessing source for details.

> <snipped>

-- 
regards,
kushal



More information about the Python-list mailing list