From 076363944826bea41b68f991d835fa30eabdf2b2 Mon Sep 17 00:00:00 2001 From: An Long Date: Fri, 28 Aug 2026 00:50:56 +0900 Subject: [PATCH 1/3] Ignore timeout in pure-Python SimpleQueue.get() when block is false --- Lib/queue.py | 4 +++- Lib/test/test_queue.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/queue.py b/Lib/queue.py index c0b359876543f7b..80db0b978b9c008 100644 --- a/Lib/queue.py +++ b/Lib/queue.py @@ -346,7 +346,9 @@ def get(self, block=True, timeout=None): available, else raise the Empty exception ('timeout' is ignored in that case). ''' - if timeout is not None and timeout < 0: + if not block: + timeout = None + elif timeout is not None and timeout < 0: raise ValueError("'timeout' must be a non-negative number") if not self._count.acquire(block, timeout): raise Empty diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py index f2898de469e349b..e1a4515500625bd 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -956,6 +956,11 @@ def test_negative_timeout_raises_exception(self): with self.assertRaises(ValueError): q.get(timeout=-1) + def test_nonblocking_ignores_timeout(self): + q = self.q + with self.assertRaises(self.queue.Empty): + q.get(block=False, timeout=-1) + def test_order(self): # Test a pair of concurrent put() and get() q = self.q From e51536c8f25b87f987a1baa7b8fcf2665d6ac2b1 Mon Sep 17 00:00:00 2001 From: An Long Date: Fri, 28 Aug 2026 00:59:20 +0900 Subject: [PATCH 2/3] Add news entry --- .../Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst diff --git a/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst b/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst new file mode 100644 index 000000000000000..aaf006ddb15566e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst @@ -0,0 +1,3 @@ +The pure Python implementation of :meth:`queue.SimpleQueue.get` now ignores +``timeout`` when ``block`` is false, matching the documented behavior and +the C implementation. It previously raised :exc:`ValueError`. From 8b1d9363302dfb87b2ec799d8266c0f529c12d37 Mon Sep 17 00:00:00 2001 From: An Long Date: Fri, 28 Aug 2026 02:41:41 +0900 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst Co-authored-by: Stan Ulbrych --- .../next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst b/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst index aaf006ddb15566e..c92fce3bc05969a 100644 --- a/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst +++ b/Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst @@ -1,3 +1,3 @@ The pure Python implementation of :meth:`queue.SimpleQueue.get` now ignores -``timeout`` when ``block`` is false, matching the documented behavior and +*timeout* when *block* is false, matching the documented behavior and the C implementation. It previously raised :exc:`ValueError`.