summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
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):