[issue3518] multiprocessing: BaseManager.from_address documented but doesn't exist
Mart Sõmermaa
report at bugs.python.org
Fri Oct 24 11:52:25 CEST 2008
Mart Sõmermaa <mrts at mrts.pri.ee> added the comment:
I propose we add the following to that section as well.
If you need to provide access to a queue from both local and remote
processes, use `multiprocessing.Queue` in the server:
>>> from multiprocessing import Process, Queue
>>> from multiprocessing.managers import BaseManager
>>> class Worker(Process):
... def __init__(self, q):
... self.q = q
... super(Worker, self).__init__()
... def run(self):
... self.q.put('local hello')
...
>>> q = Queue()
>>> w = Worker(q)
>>> w.start()
>>> class QueueManager(BaseManager): pass
...
>>> QueueManager.register('getQueue', callable=lambda: q)
>>> m = QueueManager(address=('', 50000), authkey='abracadabra')
>>> s = m.get_server()
>>> s.serve_forever()
Use it in the client as shown above:
>>> from multiprocessing.managers import BaseManager
>>> class QueueManager(BaseManager): pass
...
>>> QueueManager.register('getQueue')
>>> m = QueueManager(address=('localhost', 50000), authkey='abracadabra')
>>> m.connect()
>>> q = m.getQueue()
>>> q.get()
'local hello'
>>> q.put('remote hello')
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3518>
_______________________________________
More information about the Python-bugs-list
mailing list