Skip to content

Commit

Permalink
[3.13] gh-73159 Added clarifications in multiprocessing docs on that …
Browse files Browse the repository at this point in the history
…objects are pickled. (GH-121686) (#121727)

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 b580589)

Co-authored-by: Ulrik Södergren <[email protected]>
  • Loading branch information
miss-islington and digitalfotografen authored Jul 13, 2024
1 parent f78e1aa commit e0643d9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit e0643d9

Please sign in to comment.