From c5d041623672a4a52a2f083db08fa6ac38883f8a Mon Sep 17 00:00:00 2001 From: Laurie O Date: Thu, 4 Apr 2024 11:42:32 +1000 Subject: [PATCH 1/3] Comment reason for waking up getters after shutdown --- Lib/asyncio/queues.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py index b8156704b8fc23..a332bd2b309757 100644 --- a/Lib/asyncio/queues.py +++ b/Lib/asyncio/queues.py @@ -267,6 +267,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(): From 5b41217df27d6053e1a57d734bfbea840ff6f45b Mon Sep 17 00:00:00 2001 From: Laurie O Date: Mon, 8 Apr 2024 15:16:55 +1000 Subject: [PATCH 2/3] Mention gets are always unblocked --- Doc/library/asyncio-queue.rst | 7 ++++--- Lib/asyncio/queues.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Doc/library/asyncio-queue.rst b/Doc/library/asyncio-queue.rst index 030d4310942d7a..9b579cc1d5fdfe 100644 --- a/Doc/library/asyncio-queue.rst +++ b/Doc/library/asyncio-queue.rst @@ -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 diff --git a/Lib/asyncio/queues.py b/Lib/asyncio/queues.py index a332bd2b309757..2f3865114a84f9 100644 --- a/Lib/asyncio/queues.py +++ b/Lib/asyncio/queues.py @@ -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: From d0d5d6d74fca2026deedf838663cd7a699e33048 Mon Sep 17 00:00:00 2001 From: Laurie O Date: Mon, 8 Apr 2024 15:20:36 +1000 Subject: [PATCH 3/3] Acknowledge Yves D --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index c785d4cfa8fdc3..5f8a975edbd36e 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -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 ------