From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:13:52 +0000 (+0200) Subject: [3.12] gh-73159 Added clarifications in multiprocessing docs on that objects are... X-Git-Tag: v3.12.5~113 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b6cb209d5de4ac64ffe4e79432909967f91635cb;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-73159 Added clarifications in multiprocessing docs on that objects are pickled. (GH-121686) (#121728) gh-73159 Added clarifications in multiprocessing docs on that objects are pickled. (GH-121686) Added explicit comments about that objects are pickled when transmitted via multiprocessing queues and pipes. (cherry picked from commit b5805892d55e769335c11a994b586355720263ba) Co-authored-by: Ulrik Södergren --- diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index d6474ef975b5..f12d4e31b4fe 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -254,6 +254,7 @@ processes: p.join() Queues are thread and process safe. + Any object put into a :mod:`~multiprocessing` queue will be serialized. **Pipes** @@ -281,6 +282,8 @@ processes: of corruption from processes using different ends of the pipe at the same time. + The :meth:`~Connection.send` method serializes the the object and + :meth:`~Connection.recv` re-creates the object. Synchronization between processes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -745,6 +748,11 @@ If you use :class:`JoinableQueue` then you **must** call semaphore used to count the number of unfinished tasks may eventually overflow, raising an exception. +One difference from other Python queue implementations, is that :mod:`multiprocessing` +queues serializes all objects that are put into them using :mod:`pickle`. +The object return by the get method is a re-created object that does not share memory +with the original object. + Note that one can also create a shared queue by using a manager object -- see :ref:`multiprocessing-managers`. @@ -811,6 +819,8 @@ For an example of the usage of queues for interprocess communication see used for receiving messages and ``conn2`` can only be used for sending messages. + The :meth:`~multiprocessing.Connection.send` method serializes the the object using + :mod:`pickle` and the :meth:`~multiprocessing.Connection.recv` re-creates the object. .. class:: Queue([maxsize])