Issue3518
Created on 2008-08-07 17:46 by marketdickinson, last changed 2008-11-28 18:48 by jnoller.
| Messages (5) | |||
|---|---|---|---|
| msg70844 - (view) | Author: Mark Dickinson (marketdickinson) | Date: 2008-08-07 17:46 | |
The BaseManager.from_address method is documented at: http://docs.python.org/dev/library/multiprocessing.html#multiprocessing.ma nagers.BaseManager.from_address but it looks as though this method doesn't actually exist. In contrast, the BaseManager.connect method appears to be necessary for making remote connections, but is not documented. |
|||
| msg75140 - (view) | Author: Mart Sõmermaa (mrts) | Date: 2008-10-23 11:17 | |
The documentation should be amended as follows:
Running the following commands creates a server for a single shared
queue which remote clients can access:
>>> from multiprocessing.managers import BaseManager
>>> import Queue
>>> queue = Queue.Queue()
>>> class QueueManager(BaseManager): pass
...
>>> QueueManager.register('getQueue', callable=lambda:queue)
>>> m = QueueManager(address=('', 50000), authkey='abracadabra')
>>> s = m.get_server()
>>> s.serve_forever()
One client can access the server as follows:
>>> 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.put('hello')
Another client can also use it:
>>> 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()
|
|||
| msg75141 - (view) | Author: Mart Sõmermaa (mrts) | Date: 2008-10-23 11:55 | |
Also, it would be helpful to elaborate a bit more on: major: * how to implement a queue that is shared both locally and remotely (i.e. n local processes access the queue as well as m remote processes) minor: * blocking (assumption: q.get() blocks on socket.recv()) * timeout (assumption: the socket does not time out, e.g. q.get() blocks endlessly on socket.recv()) |
|||
| msg75156 - (view) | Author: Mart Sõmermaa (mrts) | Date: 2008-10-24 09:52 | |
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')
|
|||
| msg76546 - (view) | Author: Jesse Noller (jnoller) | Date: 2008-11-28 18:48 | |
Added the mp.managers shared queue example, fixed the docs in r67419 on trunk. merged to py3k and 2.6.1 maint |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-11-28 18:48:55 | jnoller | set | status: open -> closed resolution: fixed messages: + msg76546 |
| 2008-10-24 09:52:24 | mrts | set | messages: + msg75156 |
| 2008-10-23 11:55:12 | mrts | set | messages: + msg75141 |
| 2008-10-23 11:17:29 | mrts | set | nosy:
+ mrts messages: + msg75140 |
| 2008-08-07 17:46:07 | marketdickinson | create | |