summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-07-25 00:40:55 (GMT)
committerGitHub <noreply@github.com>2017-07-25 00:40:55 (GMT)
commitb4c52966c810b5c5e088fceff403247f610b7d13 (patch)
tree286e427b89dac215a6b077f14f0245ee40f54b42
parentffb49408f0780ae80a553208aa133bc5bb3ba129 (diff)
downloadcpython-b4c52966c810b5c5e088fceff403247f610b7d13.zip
cpython-b4c52966c810b5c5e088fceff403247f610b7d13.tar.gz
cpython-b4c52966c810b5c5e088fceff403247f610b7d13.tar.bz2
bpo-26762: test_multiprocessing close more queues (#2855)
* Close explicitly queues to make sure that we don't leave dangling threads * test_queue_in_process(): remove unused queue * test_access() joins also the process to fix a random warning
-rw-r--r--Lib/test/_test_multiprocessing.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index a87b028..e18f7cd 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -283,6 +283,7 @@ class _TestProcess(BaseTestCase):
self.assertEqual(p.exitcode, 0)
self.assertEqual(p.is_alive(), False)
self.assertNotIn(p, self.active_children())
+ close_queue(q)
@classmethod
def _sleep_some(cls):
@@ -461,6 +462,8 @@ class _TestProcess(BaseTestCase):
gc.collect()
self.assertIs(wr(), None)
+ close_queue(q)
+
def test_many_processes(self):
if self.TYPE == 'threads':
self.skipTest('test not appropriate for {}'.format(self.TYPE))
@@ -501,6 +504,7 @@ class _TestProcess(BaseTestCase):
p.join()
self.assertIs(wr(), None)
self.assertEqual(q.get(), 5)
+ close_queue(q)
@classmethod
def _test_child_fd_inflation(self, evt, q):
@@ -536,6 +540,7 @@ class _TestProcess(BaseTestCase):
evt.set()
for p in procs:
p.join()
+ close_queue(q)
#
#
@@ -721,6 +726,7 @@ class _TestQueue(BaseTestCase):
self.assertEqual(queue_full(queue, MAXSIZE), False)
proc.join()
+ close_queue(queue)
@classmethod
def _test_get(cls, queue, child_can_start, parent_can_continue):
@@ -783,6 +789,7 @@ class _TestQueue(BaseTestCase):
self.assertTimingAlmostEqual(get.elapsed, TIMEOUT3)
proc.join()
+ close_queue(queue)
@classmethod
def _test_fork(cls, queue):
@@ -818,6 +825,7 @@ class _TestQueue(BaseTestCase):
self.assertRaises(pyqueue.Empty, queue.get, False)
p.join()
+ close_queue(queue)
def test_qsize(self):
q = self.Queue()
@@ -861,6 +869,7 @@ class _TestQueue(BaseTestCase):
for p in workers:
p.join()
+ close_queue(queue)
def test_no_import_lock_contention(self):
with test.support.temp_cwd():
@@ -891,6 +900,7 @@ class _TestQueue(BaseTestCase):
# Tolerate a delta of 30 ms because of the bad clock resolution on
# Windows (usually 15.6 ms)
self.assertGreaterEqual(delta, 0.170)
+ close_queue(q)
def test_queue_feeder_donot_stop_onexc(self):
# bpo-30414: verify feeder handles exceptions correctly
@@ -1503,6 +1513,7 @@ class _TestBarrier(BaseTestCase):
self.run_threads(self._test_wait_return_f, (self.barrier, queue))
results = [queue.get() for i in range(self.N)]
self.assertEqual(results.count(0), 1)
+ close_queue(queue)
@classmethod
def _test_action_f(cls, barrier, results):
@@ -3158,6 +3169,8 @@ class _TestPicklingConnections(BaseTestCase):
w.close()
self.assertEqual(conn.recv(), 'foobar'*2)
+ p.join()
+
#
#
#
@@ -3654,7 +3667,7 @@ def _this_sub_process(q):
except pyqueue.Empty:
pass
-def _test_process(q):
+def _test_process():
queue = multiprocessing.Queue()
subProc = multiprocessing.Process(target=_this_sub_process, args=(queue,))
subProc.daemon = True
@@ -3694,8 +3707,7 @@ class _file_like(object):
class TestStdinBadfiledescriptor(unittest.TestCase):
def test_queue_in_process(self):
- queue = multiprocessing.Queue()
- proc = multiprocessing.Process(target=_test_process, args=(queue,))
+ proc = multiprocessing.Process(target=_test_process)
proc.start()
proc.join()