summaryrefslogtreecommitdiff
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-06-12 15:28:19 +0200
committerGitHub <noreply@github.com>2017-06-12 15:28:19 +0200
commitdfd5f34634f9c505945e9348b4b799544680a7cf (patch)
tree153e7ebd65c9c0777ca8a5e8758d3b54783478c4 /Lib/test/_test_multiprocessing.py
parentced36a993fcfd1c76637119d31c03156a8772e11 (diff)
downloadcpython-git-dfd5f34634f9c505945e9348b4b799544680a7cf.tar.gz
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
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py39
1 files changed, 37 insertions, 2 deletions
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)
+
#
#
#