From 00024dcf075f53dd8bda17612301b92af7521fdd Mon Sep 17 00:00:00 2001 From: PrineNaroliya Date: Wed, 3 Sep 2025 20:32:19 +0530 Subject: [PATCH] [doc] Clarify safe usage of Queue in multiprocessing 'Using a remote manager' section --- Doc/library/multiprocessing.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index d18ada3511d891..a37c6a588401b3 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -2104,7 +2104,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). @@ -2112,11 +2112,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() @@ -2145,7 +2146,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): @@ -2154,7 +2155,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