mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Merge 00024dcf07 into 7099af8f5e
This commit is contained in:
commit
7693400245
1 changed files with 8 additions and 6 deletions
|
|
@ -2117,7 +2117,7 @@ callables with the manager class. For example::
|
|||
|
||||
|
||||
Using a remote manager
|
||||
""""""""""""""""""""""
|
||||
"""""""""""""""""""""""
|
||||
|
||||
It is possible to run a manager server on one machine and have clients use it
|
||||
from other machines (assuming that the firewalls involved allow it).
|
||||
|
|
@ -2125,11 +2125,12 @@ from other machines (assuming that the firewalls involved allow it).
|
|||
Running the following commands creates a server for a single shared queue which
|
||||
remote clients can access::
|
||||
|
||||
>>> from multiprocessing import Manager
|
||||
>>> from multiprocessing.managers import BaseManager
|
||||
>>> from queue import Queue
|
||||
>>> queue = Queue()
|
||||
>>> manager = Manager()
|
||||
>>> queue = manager.Queue()
|
||||
>>> class QueueManager(BaseManager): pass
|
||||
>>> QueueManager.register('get_queue', callable=lambda:queue)
|
||||
>>> QueueManager.register('get_queue', callable=lambda: queue)
|
||||
>>> m = QueueManager(address=('', 50000), authkey=b'abracadabra')
|
||||
>>> s = m.get_server()
|
||||
>>> s.serve_forever()
|
||||
|
|
@ -2158,7 +2159,7 @@ Another client can also use it::
|
|||
Local processes can also access that queue, using the code from above on the
|
||||
client to access it remotely::
|
||||
|
||||
>>> from multiprocessing import Process, Queue
|
||||
>>> from multiprocessing import Process, Manager
|
||||
>>> from multiprocessing.managers import BaseManager
|
||||
>>> class Worker(Process):
|
||||
... def __init__(self, q):
|
||||
|
|
@ -2167,7 +2168,8 @@ client to access it remotely::
|
|||
... def run(self):
|
||||
... self.q.put('local hello')
|
||||
...
|
||||
>>> queue = Queue()
|
||||
>>> manager = Manager()
|
||||
>>> queue = manager.Queue()
|
||||
>>> w = Worker(queue)
|
||||
>>> w.start()
|
||||
>>> class QueueManager(BaseManager): pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue