Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-96471: Correct documentation for asyncio queue shutdown #117621

Merged
merged 3 commits into from Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions Doc/library/asyncio-queue.rst
Expand Up @@ -106,9 +106,10 @@ Queue
raise once the queue is empty. Set *immediate* to true to make
:meth:`~Queue.get` raise immediately instead.

All blocked callers of :meth:`~Queue.put` will be unblocked. If
*immediate* is true, also unblock callers of :meth:`~Queue.get`
and :meth:`~Queue.join`.
All blocked callers of :meth:`~Queue.put` and :meth:`~Queue.get`
will be unblocked. If *immediate* is true, a task will be marked
as done for each remaining item in the queue, which may unblock
callers of :meth:`~Queue.join`.

.. versionadded:: 3.13

Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Expand Up @@ -298,7 +298,7 @@ asyncio

* Add :meth:`asyncio.Queue.shutdown` (along with
:exc:`asyncio.QueueShutDown`) for queue termination.
(Contributed by Laurie Opperman in :gh:`104228`.)
(Contributed by Laurie Opperman and Yves Duprat in :gh:`104228`.)

base64
------
Expand Down
6 changes: 4 additions & 2 deletions Lib/asyncio/queues.py
Expand Up @@ -256,8 +256,9 @@ def shutdown(self, immediate=False):
By default, gets will only raise once the queue is empty. Set
'immediate' to True to make gets raise immediately instead.

All blocked callers of put() will be unblocked, and also get()
and join() if 'immediate'.
All blocked callers of put() and get() will be unblocked. If
'immediate', a task is marked as done for each item remaining in
the queue, which may unblock callers of join().
"""
self._is_shutdown = True
if immediate:
Expand All @@ -267,6 +268,7 @@ def shutdown(self, immediate=False):
self._unfinished_tasks -= 1
if self._unfinished_tasks == 0:
self._finished.set()
# All getters need to re-check queue-empty to raise ShutDown
while self._getters:
getter = self._getters.popleft()
if not getter.done():
Expand Down