summaryrefslogtreecommitdiffstats
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-07-14 10:24:58 (GMT)
committerGitHub <noreply@github.com>2024-07-14 10:24:58 (GMT)
commitdfedbdba402448d6ed7ea3cf13772305c7959eee (patch)
treeb2d8a0a916139d55b2c5b6f35bbb8f49dbdb6892 /Lib/test/_test_multiprocessing.py
parentf17057dab10b2114614d9d59291ebbc0bc9ab787 (diff)
downloadcpython-dfedbdba402448d6ed7ea3cf13772305c7959eee.zip
cpython-dfedbdba402448d6ed7ea3cf13772305c7959eee.tar.gz
cpython-dfedbdba402448d6ed7ea3cf13772305c7959eee.tar.bz2
[3.13] gh-120012: clarify the behaviour of `multiprocessing.Queue.empty` on closed queues. (GH-120102) (#120469)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index f126b67..5dae370 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -1332,6 +1332,23 @@ class _TestQueue(BaseTestCase):
self.assertTrue(not_serializable_obj.reduce_was_called)
self.assertTrue(not_serializable_obj.on_queue_feeder_error_was_called)
+ def test_closed_queue_empty_exceptions(self):
+ # Assert that checking the emptiness of an unused closed queue
+ # does not raise an OSError. The rationale is that q.close() is
+ # a no-op upon construction and becomes effective once the queue
+ # has been used (e.g., by calling q.put()).
+ for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
+ q.close() # this is a no-op since the feeder thread is None
+ q.join_thread() # this is also a no-op
+ self.assertTrue(q.empty())
+
+ for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
+ q.put('foo') # make sure that the queue is 'used'
+ q.close() # close the feeder thread
+ q.join_thread() # make sure to join the feeder thread
+ with self.assertRaisesRegex(OSError, 'is closed'):
+ q.empty()
+
def test_closed_queue_put_get_exceptions(self):
for q in multiprocessing.Queue(), multiprocessing.JoinableQueue():
q.close()
@@ -5815,6 +5832,15 @@ class TestSimpleQueue(unittest.TestCase):
finally:
parent_can_continue.set()
+ def test_empty_exceptions(self):
+ # Assert that checking emptiness of a closed queue raises
+ # an OSError, independently of whether the queue was used
+ # or not. This differs from Queue and JoinableQueue.
+ q = multiprocessing.SimpleQueue()
+ q.close() # close the pipe
+ with self.assertRaisesRegex(OSError, 'is closed'):
+ q.empty()
+
def test_empty(self):
queue = multiprocessing.SimpleQueue()
child_can_start = multiprocessing.Event()