Message75156
| Author |
mrts |
| Recipients |
jnoller, mark.dickinson, mrts |
| Date |
2008年10月24日.09:52:23 |
| SpamBayes Score |
0.0001539359 |
| Marked as misclassified |
No |
| Message-id |
<1224841945.85.0.28812877642.issue3518@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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') |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2008年10月24日 09:52:26 | mrts | set | recipients:
+ mrts, mark.dickinson, jnoller |
| 2008年10月24日 09:52:25 | mrts | set | messageid: <1224841945.85.0.28812877642.issue3518@psf.upfronthosting.co.za> |
| 2008年10月24日 09:52:24 | mrts | link | issue3518 messages |
| 2008年10月24日 09:52:23 | mrts | create |
|