Skip to content

Commit 45e5b1b

Browse files
gh-156476: Ignore timeout in _PySimpleQueue.get() when block is false (#156477)
Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent eb08902 commit 45e5b1b

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
@@ -956,6 +956,11 @@ def test_negative_timeout_raises_exception(self):
956956
with self.assertRaises(ValueError):
957957
q.get(timeout=-1)
958958

959+
def test_nonblocking_ignores_timeout(self):
960+
q = self.q
961+
with self.assertRaises(self.queue.Empty):
962+
q.get(block=False, timeout=-1)
963+
959964
def test_order(self):
960965
# Test a pair of concurrent put() and get()
961966
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)