https://github.com/python/cpython/commit/6e722281203d04567d6cade58f8ff86e3fe50806
commit: 6e722281203d04567d6cade58f8ff86e3fe50806
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-08-27T19:05:18Z
summary:

[3.13] gh-156476: Ignore timeout in `_PySimpleQueue.get()` when block is false 
(GH-156477) (#156489)

(cherry picked from commit 45e5b1b0a97795e2ac82a306ce366efd55bd15b4)

Co-authored-by: An Long <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-08-28-00-59-00.gh-issue-156476.rQhxc7.rst
M Lib/queue.py
M Lib/test/test_queue.py

diff --git a/Lib/queue.py b/Lib/queue.py
index c0b359876543f7..80db0b978b9c00 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 fb2be84f493995..54ebd41e040217 100644
--- a/Lib/test/test_queue.py
+++ b/Lib/test/test_queue.py
@@ -955,6 +955,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
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 00000000000000..c92fce3bc05969
--- /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`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to