Mart Sõmermaa <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue3518>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to