From dfd5f34634f9c505945e9348b4b799544680a7cf Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 12 Jun 2017 15:28:19 +0200 Subject: Fix bpo-30589: improve Process.exitcode with forkserver (#1989) * Fix bpo-30589: improve Process.exitcode with forkserver When the child is killed, Process.exitcode should return -signum, not 255. * Add Misc/NEWS --- Lib/test/_test_multiprocessing.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'Lib/test/_test_multiprocessing.py') diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index f1f9367493..70ecc54bfe 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -274,6 +274,10 @@ class _TestProcess(BaseTestCase): def _test_terminate(cls): time.sleep(100) + @classmethod + def _test_sleep(cls, delay): + time.sleep(delay) + def test_terminate(self): if self.TYPE == 'threads': self.skipTest('test not appropriate for {}'.format(self.TYPE)) @@ -323,8 +327,9 @@ class _TestProcess(BaseTestCase): p.join() - # XXX sometimes get p.exitcode == 0 on Windows ... - #self.assertEqual(p.exitcode, -signal.SIGTERM) + # sometimes get p.exitcode == 0 on Windows ... + if os.name != 'nt': + self.assertEqual(p.exitcode, -signal.SIGTERM) def test_cpu_count(self): try: @@ -398,6 +403,36 @@ class _TestProcess(BaseTestCase): p.join() self.assertTrue(wait_for_handle(sentinel, timeout=1)) + def test_many_processes(self): + if self.TYPE == 'threads': + self.skipTest('test not appropriate for {}'.format(self.TYPE)) + + sm = multiprocessing.get_start_method() + N = 5 if sm == 'spawn' else 100 + + # Try to overwhelm the forkserver loop with events + procs = [self.Process(target=self._test_sleep, args=(0.01,)) + for i in range(N)] + for p in procs: + p.start() + for p in procs: + p.join(timeout=10) + for p in procs: + self.assertEqual(p.exitcode, 0) + + procs = [self.Process(target=self._test_terminate) + for i in range(N)] + for p in procs: + p.start() + time.sleep(0.001) # let the children start... + for p in procs: + p.terminate() + for p in procs: + p.join(timeout=10) + if os.name != 'nt': + for p in procs: + self.assertEqual(p.exitcode, -signal.SIGTERM) + # # # -- cgit v1.2.1