Skip to content

Commit 6e72228

Browse files
miss-islingtonaiskStanFromIreland
authored
[3.13] gh-156476: Ignore timeout in _PySimpleQueue.get() when block is false (GH-156477) (#156489)
(cherry picked from commit 45e5b1b) Co-authored-by: An Long <aisk@users.noreply.github.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent c6d191d commit 6e72228

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/queue.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ def get(self, block=True, timeout=None):
346346
available, else raise the Empty exception ('timeout' is ignored
347347
in that case).
348348
'''
349-
if timeout is not None and timeout < 0:
349+
if not block:
350+
timeout = None
351+
elif timeout is not None and timeout < 0:
350352
raise ValueError("'timeout' must be a non-negative number")
351353
if not self._count.acquire(block, timeout):
352354
raise Empty

Lib/test/test_queue.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,11 @@ def test_negative_timeout_raises_exception(self):
955955
with self.assertRaises(ValueError):
956956
q.get(timeout=-1)
957957

958+
def test_nonblocking_ignores_timeout(self):
959+
q = self.q
960+
with self.assertRaises(self.queue.Empty):
961+
q.get(block=False, timeout=-1)
962+
958963
def test_order(self):
959964
# Test a pair of concurrent put() and get()
960965
q = self.q
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The pure Python implementation of :meth:`queue.SimpleQueue.get` now ignores
2+
*timeout* when *block* is false, matching the documented behavior and
3+
the C implementation. It previously raised :exc:`ValueError`.

0 commit comments

Comments
 (0)