gh-156476: Ignore timeout in `_PySimpleQueue.get()` when block is fal… · python/cpython@45e5b1b

GitHub

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-iftimeoutisnotNoneandtimeout<0:

349+ifnotblock:

350+timeout=None

351+eliftimeoutisnotNoneandtimeout<0:

350352raiseValueError("'timeout' must be a non-negative number")

351353ifnotself._count.acquire(block, timeout):

352354raiseEmpty

Original file line numberDiff line numberDiff line change@@ -956,6 +956,11 @@ def test_negative_timeout_raises_exception(self):

956956withself.assertRaises(ValueError):

957957q.get(timeout=-1)

958958959+deftest_nonblocking_ignores_timeout(self):

960+q=self.q

961+withself.assertRaises(self.queue.Empty):

962+q.get(block=False, timeout=-1)

963+959964deftest_order(self):

960965# Test a pair of concurrent put() and get()

961966q=self.q

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`.