cpython: 3585cb1388f2 (original) (raw)
--- a/Lib/multiprocessing/pool.py +++ b/Lib/multiprocessing/pool.py @@ -576,6 +576,7 @@ class MapResult(ApplyResult): if chunksize <= 0: self._number_left = 0 self._event.set()
del cache[self._job][](#l1.7) else:[](#l1.8) self._number_left = length//chunksize + bool(length % chunksize)[](#l1.9)
--- a/Lib/multiprocessing/process.py +++ b/Lib/multiprocessing/process.py @@ -262,11 +262,11 @@ class Process(object): except SystemExit as e: if not e.args: exitcode = 1
elif type(e.args[0]) is int:[](#l2.7)
elif isinstance(e.args[0], int):[](#l2.8) exitcode = e.args[0][](#l2.9) else:[](#l2.10)
sys.stderr.write(e.args[0] + '\n')[](#l2.11)
exitcode = 1[](#l2.12)
sys.stderr.write(str(e.args[0]) + '\n')[](#l2.13)
exitcode = 0 if isinstance(e.args[0], str) else 1[](#l2.14) except:[](#l2.15) exitcode = 1[](#l2.16) import traceback[](#l2.17)
--- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -439,6 +439,36 @@ class _TestSubclassingProcess(BaseTestCa 1/0 # MARKER
- @classmethod
- def _test_sys_exit(cls, reason, testfn):
sys.stderr = open(testfn, 'w')[](#l3.9)
sys.exit(reason)[](#l3.10)
- def test_sys_exit(self):
# See Issue 13854[](#l3.13)
if self.TYPE == 'threads':[](#l3.14)
return[](#l3.15)
testfn = test.support.TESTFN[](#l3.17)
self.addCleanup(test.support.unlink, testfn)[](#l3.18)
for reason, code in (([1, 2, 3], 1), ('ignore this', 0)):[](#l3.20)
p = self.Process(target=self._test_sys_exit, args=(reason, testfn))[](#l3.21)
p.daemon = True[](#l3.22)
p.start()[](#l3.23)
p.join(5)[](#l3.24)
self.assertEqual(p.exitcode, code)[](#l3.25)
with open(testfn, 'r') as f:[](#l3.27)
self.assertEqual(f.read().rstrip(), str(reason))[](#l3.28)
for reason in (True, False, 8):[](#l3.30)
p = self.Process(target=sys.exit, args=(reason,))[](#l3.31)
p.daemon = True[](#l3.32)
p.start()[](#l3.33)
p.join(5)[](#l3.34)
self.assertEqual(p.exitcode, reason)[](#l3.35)
+ # # # @@ -1342,6 +1372,18 @@ class _TestPool(BaseTestCase): join() self.assertLess(join.elapsed, 0.5)
self.assertEqual(p.map(sqr, []), [])[](#l3.48)
self.assertEqual(list(p.imap(sqr, [])), [])[](#l3.49)
self.assertEqual(list(p.imap_unordered(sqr, [])), [])[](#l3.50)
self.assertEqual(p.map_async(sqr, []).get(), [])[](#l3.51)
p.close()[](#l3.53)
p.join()[](#l3.54)
+ def raising(): raise KeyError("key") @@ -2487,7 +2529,7 @@ class ProcessesMixin(object): 'Queue', 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition', 'Event', 'Value', 'Array', 'RawValue', 'RawArray', 'current_process', 'active_children', 'Pipe',
'connection', 'JoinableQueue'[](#l3.63)
'connection', 'JoinableQueue', 'Pool'[](#l3.64) )))[](#l3.65)
testcases_processes = create_test_cases(ProcessesMixin, type='processes') @@ -2501,7 +2543,7 @@ class ManagerMixin(object): locals().update(get_attributes(manager, ( 'Queue', 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition', 'Event', 'Value', 'Array', 'list', 'dict',
'Namespace', 'JoinableQueue'[](#l3.72)
'Namespace', 'JoinableQueue', 'Pool'[](#l3.73) )))[](#l3.74)
testcases_manager = create_test_cases(ManagerMixin, type='manager') @@ -2515,7 +2557,7 @@ class ThreadsMixin(object): 'Queue', 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition', 'Event', 'Value', 'Array', 'current_process', 'active_children', 'Pipe', 'connection', 'dict', 'list',
'Namespace', 'JoinableQueue'[](#l3.81)
'Namespace', 'JoinableQueue', 'Pool'[](#l3.82) )))[](#l3.83)
testcases_threads = create_test_cases(ThreadsMixin, type='threads')
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -21,6 +21,12 @@ Core and Builtins Library ------- +- Issue #13854: Make multiprocessing properly handle non-integer