Commit 11f0807a authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-31234: test_multiprocessing: wait 30 seconds (#3599)

Give 30 seconds to join_process(), instead of 5 or 10 seconds, to
wait until the process completes.
parent da3e5cf9
...@@ -63,6 +63,9 @@ except ImportError: ...@@ -63,6 +63,9 @@ except ImportError:
# #
# #
# Timeout to wait until a process completes
TIMEOUT = 30.0 # seconds
def latin(s): def latin(s):
return s.encode('latin') return s.encode('latin')
...@@ -73,10 +76,10 @@ def close_queue(queue): ...@@ -73,10 +76,10 @@ def close_queue(queue):
queue.join_thread() queue.join_thread()
def join_process(process, timeout): def join_process(process):
# Since multiprocessing.Process has the same API than threading.Thread # Since multiprocessing.Process has the same API than threading.Thread
# (join() and is_alive(), the support function can be reused # (join() and is_alive(), the support function can be reused
support.join_thread(process, timeout) support.join_thread(process, timeout=TIMEOUT)
# #
...@@ -484,7 +487,7 @@ class _TestProcess(BaseTestCase): ...@@ -484,7 +487,7 @@ class _TestProcess(BaseTestCase):
for p in procs: for p in procs:
p.start() p.start()
for p in procs: for p in procs:
join_process(p, timeout=10) join_process(p)
for p in procs: for p in procs:
self.assertEqual(p.exitcode, 0) self.assertEqual(p.exitcode, 0)
...@@ -496,7 +499,7 @@ class _TestProcess(BaseTestCase): ...@@ -496,7 +499,7 @@ class _TestProcess(BaseTestCase):
for p in procs: for p in procs:
p.terminate() p.terminate()
for p in procs: for p in procs:
join_process(p, timeout=10) join_process(p)
if os.name != 'nt': if os.name != 'nt':
for p in procs: for p in procs:
self.assertEqual(p.exitcode, -signal.SIGTERM) self.assertEqual(p.exitcode, -signal.SIGTERM)
...@@ -659,7 +662,7 @@ class _TestSubclassingProcess(BaseTestCase): ...@@ -659,7 +662,7 @@ class _TestSubclassingProcess(BaseTestCase):
p = self.Process(target=self._test_sys_exit, args=(reason, testfn)) p = self.Process(target=self._test_sys_exit, args=(reason, testfn))
p.daemon = True p.daemon = True
p.start() p.start()
join_process(p, timeout=5) join_process(p)
self.assertEqual(p.exitcode, 1) self.assertEqual(p.exitcode, 1)
with open(testfn, 'r') as f: with open(testfn, 'r') as f:
...@@ -672,7 +675,7 @@ class _TestSubclassingProcess(BaseTestCase): ...@@ -672,7 +675,7 @@ class _TestSubclassingProcess(BaseTestCase):
p = self.Process(target=sys.exit, args=(reason,)) p = self.Process(target=sys.exit, args=(reason,))
p.daemon = True p.daemon = True
p.start() p.start()
join_process(p, timeout=5) join_process(p)
self.assertEqual(p.exitcode, reason) self.assertEqual(p.exitcode, reason)
# #
...@@ -1261,7 +1264,7 @@ class _TestCondition(BaseTestCase): ...@@ -1261,7 +1264,7 @@ class _TestCondition(BaseTestCase):
state.value += 1 state.value += 1
cond.notify() cond.notify()
join_process(p, timeout=5) join_process(p)
self.assertEqual(p.exitcode, 0) self.assertEqual(p.exitcode, 0)
@classmethod @classmethod
...@@ -1288,7 +1291,7 @@ class _TestCondition(BaseTestCase): ...@@ -1288,7 +1291,7 @@ class _TestCondition(BaseTestCase):
args=(cond, state, success, sem)) args=(cond, state, success, sem))
p.daemon = True p.daemon = True
p.start() p.start()
self.assertTrue(sem.acquire(timeout=10)) self.assertTrue(sem.acquire(timeout=TIMEOUT))
# Only increment 3 times, so state == 4 is never reached. # Only increment 3 times, so state == 4 is never reached.
for i in range(3): for i in range(3):
...@@ -1297,7 +1300,7 @@ class _TestCondition(BaseTestCase): ...@@ -1297,7 +1300,7 @@ class _TestCondition(BaseTestCase):
state.value += 1 state.value += 1
cond.notify() cond.notify()
join_process(p, timeout=5) join_process(p)
self.assertTrue(success.value) self.assertTrue(success.value)
@classmethod @classmethod
...@@ -3079,7 +3082,7 @@ class _TestPicklingConnections(BaseTestCase): ...@@ -3079,7 +3082,7 @@ class _TestPicklingConnections(BaseTestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
from multiprocessing import resource_sharer from multiprocessing import resource_sharer
resource_sharer.stop(timeout=5) resource_sharer.stop(timeout=TIMEOUT)
@classmethod @classmethod
def _listener(cls, conn, families): def _listener(cls, conn, families):
...@@ -4011,7 +4014,7 @@ class TestTimeouts(unittest.TestCase): ...@@ -4011,7 +4014,7 @@ class TestTimeouts(unittest.TestCase):
self.assertEqual(conn.recv(), 456) self.assertEqual(conn.recv(), 456)
conn.close() conn.close()
l.close() l.close()
join_process(p, timeout=10) join_process(p)
finally: finally:
socket.setdefaulttimeout(old_timeout) socket.setdefaulttimeout(old_timeout)
...@@ -4047,7 +4050,7 @@ class TestForkAwareThreadLock(unittest.TestCase): ...@@ -4047,7 +4050,7 @@ class TestForkAwareThreadLock(unittest.TestCase):
p = multiprocessing.Process(target=cls.child, args=(n-1, conn)) p = multiprocessing.Process(target=cls.child, args=(n-1, conn))
p.start() p.start()
conn.close() conn.close()
join_process(p, timeout=5) join_process(p)
else: else:
conn.send(len(util._afterfork_registry)) conn.send(len(util._afterfork_registry))
conn.close() conn.close()
...@@ -4060,7 +4063,7 @@ class TestForkAwareThreadLock(unittest.TestCase): ...@@ -4060,7 +4063,7 @@ class TestForkAwareThreadLock(unittest.TestCase):
p.start() p.start()
w.close() w.close()
new_size = r.recv() new_size = r.recv()
join_process(p, timeout=5) join_process(p)
self.assertLessEqual(new_size, old_size) self.assertLessEqual(new_size, old_size)
# #
...@@ -4115,7 +4118,7 @@ class TestCloseFds(unittest.TestCase): ...@@ -4115,7 +4118,7 @@ class TestCloseFds(unittest.TestCase):
p.start() p.start()
writer.close() writer.close()
e = reader.recv() e = reader.recv()
join_process(p, timeout=5) join_process(p)
finally: finally:
self.close(fd) self.close(fd)
writer.close() writer.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment