summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-04-27 16:11:10 (GMT)
committerGitHub <noreply@github.com>2020-04-27 16:11:10 (GMT)
commit9adccc1384568f4d46e37f698cb3e3a4f6ca0252 (patch)
treef12424600659c0171b2f70f6ab97060c9a31b977 /Lib
parentc5c42815ecb560bbf34db99b0e15fe9b604be889 (diff)
downloadcpython-9adccc1384568f4d46e37f698cb3e3a4f6ca0252.zip
cpython-9adccc1384568f4d46e37f698cb3e3a4f6ca0252.tar.gz
cpython-9adccc1384568f4d46e37f698cb3e3a4f6ca0252.tar.bz2
bpo-30966: Add multiprocessing.SimpleQueue.close() (GH-19735)
Add a new close() method to multiprocessing.SimpleQueue to explicitly close the queue. Automerge-Triggered-By: @pitrou
Diffstat (limited to 'Lib')
-rw-r--r--Lib/multiprocessing/queues.py4
-rw-r--r--Lib/test/_test_multiprocessing.py14
2 files changed, 18 insertions, 0 deletions
diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index c0a284d..a290181 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -346,6 +346,10 @@ class SimpleQueue(object):
else:
self._wlock = ctx.Lock()
+ def close(self):
+ self._reader.close()
+ self._writer.close()
+
def empty(self):
return not self._poll()
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 083ad53..dd894f2 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -5244,6 +5244,20 @@ class TestSimpleQueue(unittest.TestCase):
proc.join()
+ def test_close(self):
+ queue = multiprocessing.SimpleQueue()
+ queue.close()
+ # closing a queue twice should not fail
+ queue.close()
+
+ # Test specific to CPython since it tests private attributes
+ @test.support.cpython_only
+ def test_closed(self):
+ queue = multiprocessing.SimpleQueue()
+ queue.close()
+ self.assertTrue(queue._reader.closed)
+ self.assertTrue(queue._writer.closed)
+
class TestPoolNotLeakOnFailure(unittest.TestCase):