Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6a5fc24
Initial commits
YvesDup Sep 11, 2025
7a98c3a
📜🤖 Added by blurb_it.
blurb-it[bot] Sep 12, 2025
297a460
Fix nits
YvesDup Sep 12, 2025
603264c
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Sep 12, 2025
9b226c0
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Sep 18, 2025
4ff001b
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Oct 29, 2025
bab07dd
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Nov 11, 2025
243068f
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Nov 25, 2025
a2d25a4
Merge branch 'python:main' into queue-shutdown-multiprocessing
YvesDup Feb 1, 2026
148ffaf
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Feb 12, 2026
bc57173
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Feb 17, 2026
247f7a9
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Apr 5, 2026
293c2e3
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Apr 21, 2026
9b7d141
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup May 29, 2026
93fe64b
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Jun 4, 2026
5981aaf
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Jun 17, 2026
7c6f69b
Add ``Queue.ShutDown`` documentation.
YvesDup Jun 19, 2026
640798f
Remove inappropiate assertion
YvesDup Jun 21, 2026
537fd85
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Jun 21, 2026
3d47640
Refactor two tests
YvesDup Jun 23, 2026
1ad46c7
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Jul 14, 2026
ccdf821
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Jul 30, 2026
54d1ae9
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Oct 6, 2026
2859437
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Oct 7, 2026
a20465a
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Oct 13, 2026
b1b1748
Merge branch 'main' into queue-shutdown-multiprocessing
YvesDup Oct 24, 2026
e540ce3
s/3.16/next/
gpshead Nov 11, 2026
f71d8bc
s/3.16/next/
gpshead Nov 11, 2026
2297146
retrieved per smontanaro
gpshead Nov 11, 2026
11d4089
Merge branch 'main' into queue-shutdown-multiprocessing
gpshead Nov 11, 2026
a5bf5f3
gh-96471: Reimplement multiprocessing.Queue.shutdown()
gpshead Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,7 @@ For an example of the usage of queues for interprocess communication see
standard library's :mod:`queue` module are raised to signal timeouts.

:class:`Queue` implements all the methods of :class:`queue.Queue` except for
:meth:`~queue.Queue.task_done`, :meth:`~queue.Queue.join`, and
:meth:`~queue.Queue.shutdown`.
:meth:`~queue.Queue.task_done` and :meth:`~queue.Queue.join`.

.. method:: qsize()

Expand Down Expand Up @@ -980,6 +979,11 @@ For an example of the usage of queues for interprocess communication see
If the queue is closed, :exc:`ValueError` is raised instead of
:exc:`AssertionError`.

Raises :exc:`queue.ShutDown` if the queue has been shut down.

.. versionchanged:: next
:exc:`queue.ShutDown` is raised if the queue has been shut down.

.. method:: put_nowait(obj)

Equivalent to ``put(obj, False)``.
Expand All @@ -998,10 +1002,65 @@ For an example of the usage of queues for interprocess communication see
If the queue is closed, :exc:`ValueError` is raised instead of
:exc:`OSError`.

Raises :exc:`queue.ShutDown` if the queue has been shut down and is
empty, or if the queue has been shut down immediately.

.. versionchanged:: next
:exc:`queue.ShutDown` is raised if the queue has been shut down.

.. method:: get_nowait()

Equivalent to ``get(False)``.

.. method:: shutdown(immediate=False)

Put the queue into a shutdown mode, in every process which uses it.

The queue can no longer grow.
Future calls to :meth:`put` raise :exc:`queue.ShutDown`.
Currently blocked callers of :meth:`put` will be unblocked
and will raise :exc:`queue.ShutDown` in the formerly blocked process.

If *immediate* is false (the default), the queue can be wound
down normally with :meth:`get` calls to extract the items which have
already been put, including those which a process has put but which
its feeder thread has not yet written to the pipe.

Once the queue is empty, future calls to :meth:`get` will raise
:exc:`queue.ShutDown`. Currently blocked callers of :meth:`get` are
unblocked and raise :exc:`queue.ShutDown` as well.

If *immediate* is true, the items remaining in the queue are discarded
instead, including those which other processes have put but not yet
written to the pipe. All callers of :meth:`get` are unblocked.

Calling :meth:`shutdown` more than once is allowed. A queue which has
been shut down cannot be put back into service.

Raises :exc:`ValueError` if the queue has been closed in this process
with :meth:`close`.

.. note::

A getter is woken up by the getter woken before it, so the
:exc:`queue.ShutDown` exception can only reach all of the blocked
processes as long as none of them is killed, or exits without
flushing its feeder thread (see :meth:`cancel_join_thread`), as it
is being woken.

Similarly, if a process is killed or exits without flushing its
feeder thread after putting items on the queue, the queue may never
be considered empty and :meth:`get` may block instead of raising
:exc:`queue.ShutDown`.

.. note::

On Windows, an item which another process is writing to the pipe
while ``shutdown(immediate=True)`` is running may still be returned
by a later :meth:`get`.

.. versionadded:: next

:class:`multiprocessing.Queue` has a few additional methods not found in
:class:`queue.Queue`. These methods are usually unnecessary for most
code:
Expand Down Expand Up @@ -1104,6 +1163,10 @@ For an example of the usage of queues for interprocess communication see
Raises a :exc:`ValueError` if called more times than there were items
placed in the queue.

.. versionchanged:: next
Items discarded by ``shutdown(immediate=True)`` count as processed:
:meth:`task_done` must not be called for them.


.. method:: join()

Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ multiprocessing
``N=buffersize-processes`` arguments).
(Contributed by Oleksandr Baltian in :gh:`136871`.)

* Add :meth:`multiprocessing.Queue.shutdown` to terminate a
:class:`multiprocessing.Queue` or a :class:`multiprocessing.JoinableQueue`
in every process which uses it, like :meth:`queue.Queue.shutdown`.
(Contributed by Yves Duprat and Gregory P. Smith in :gh:`96471`.)


os
--
Expand Down
Loading
Loading