Skip to content

Commit 00024dc

Browse files
[doc] Clarify safe usage of Queue in multiprocessing 'Using a remote manager' section
1 parent 3706ef6 commit 00024dc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Doc/library/multiprocessing.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,19 +2104,20 @@ callables with the manager class. For example::
21042104

21052105

21062106
Using a remote manager
2107-
""""""""""""""""""""""
2107+
"""""""""""""""""""""""
21082108

21092109
It is possible to run a manager server on one machine and have clients use it
21102110
from other machines (assuming that the firewalls involved allow it).
21112111

21122112
Running the following commands creates a server for a single shared queue which
21132113
remote clients can access::
21142114

2115+
>>> from multiprocessing import Manager
21152116
>>> from multiprocessing.managers import BaseManager
2116-
>>> from queue import Queue
2117-
>>> queue = Queue()
2117+
>>> manager = Manager()
2118+
>>> queue = manager.Queue()
21182119
>>> class QueueManager(BaseManager): pass
2119-
>>> QueueManager.register('get_queue', callable=lambda:queue)
2120+
>>> QueueManager.register('get_queue', callable=lambda: queue)
21202121
>>> m = QueueManager(address=('', 50000), authkey=b'abracadabra')
21212122
>>> s = m.get_server()
21222123
>>> s.serve_forever()
@@ -2145,7 +2146,7 @@ Another client can also use it::
21452146
Local processes can also access that queue, using the code from above on the
21462147
client to access it remotely::
21472148

2148-
>>> from multiprocessing import Process, Queue
2149+
>>> from multiprocessing import Process, Manager
21492150
>>> from multiprocessing.managers import BaseManager
21502151
>>> class Worker(Process):
21512152
... def __init__(self, q):
@@ -2154,7 +2155,8 @@ client to access it remotely::
21542155
... def run(self):
21552156
... self.q.put('local hello')
21562157
...
2157-
>>> queue = Queue()
2158+
>>> manager = Manager()
2159+
>>> queue = manager.Queue()
21582160
>>> w = Worker(queue)
21592161
>>> w.start()
21602162
>>> class QueueManager(BaseManager): pass

0 commit comments

Comments
 (0)