cpython: 96c1de5acbd3 (original) (raw)
Mercurial > cpython
changeset 74653:96c1de5acbd3
Issue #13812: When a multiprocessing Process child raises an exception, flush stderr after printing the exception traceback. [#13812]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Fri, 27 Jan 2012 10:53:35 +0100 |
parents | 849e113ddf83(current diff)2863d9273abd(diff) |
children | d35a25a25cb3 |
files | Lib/multiprocessing/forking.py Lib/multiprocessing/process.py Lib/test/test_multiprocessing.py Misc/NEWS |
diffstat | 4 files changed, 30 insertions(+), 5 deletions(-)[+] [-] Lib/multiprocessing/forking.py 2 Lib/multiprocessing/process.py 7 Lib/test/test_multiprocessing.py 23 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -129,8 +129,6 @@ if sys.platform != 'win32': import random random.seed() code = process_obj._bootstrap()
sys.stdout.flush()[](#l1.7)
sys.stderr.flush()[](#l1.8) os._exit(code)[](#l1.9)
# w
will be closed when the child exits, at which point r
--- a/Lib/multiprocessing/process.py +++ b/Lib/multiprocessing/process.py @@ -291,16 +291,17 @@ class Process(object): exitcode = e.args[0] else: sys.stderr.write(e.args[0] + '\n')
sys.stderr.flush()[](#l2.7) exitcode = 1[](#l2.8) except:[](#l2.9) exitcode = 1[](#l2.10) import traceback[](#l2.11) sys.stderr.write('Process %s:\n' % self.name)[](#l2.12)
traceback.print_exc()[](#l2.13)
finally:[](#l2.14)
util.info('process exiting with exitcode %d' % exitcode)[](#l2.15)
sys.stdout.flush()[](#l2.16) sys.stderr.flush()[](#l2.17)
traceback.print_exc()[](#l2.18)
util.info('process exiting with exitcode %d' % exitcode)[](#l2.20) return exitcode[](#l2.21)
--- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -417,6 +417,29 @@ class _TestSubclassingProcess(BaseTestCa uppercaser.stop() uppercaser.join()
- def test_stderr_flush(self):
# sys.stderr is flushed at process shutdown (issue #13812)[](#l3.8)
if self.TYPE == "threads":[](#l3.9)
return[](#l3.10)
testfn = test.support.TESTFN[](#l3.12)
self.addCleanup(test.support.unlink, testfn)[](#l3.13)
proc = self.Process(target=self._test_stderr_flush, args=(testfn,))[](#l3.14)
proc.start()[](#l3.15)
proc.join()[](#l3.16)
with open(testfn, 'r') as f:[](#l3.17)
err = f.read()[](#l3.18)
# The whole traceback was printed[](#l3.19)
self.assertIn("ZeroDivisionError", err)[](#l3.20)
self.assertIn("test_multiprocessing.py", err)[](#l3.21)
self.assertIn("1/0 # MARKER", err)[](#l3.22)
- @classmethod
- def _test_stderr_flush(cls, testfn):
sys.stderr = open(testfn, 'w')[](#l3.26)
1/0 # MARKER[](#l3.27)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -461,6 +461,9 @@ Core and Builtins Library ------- +- Issue #13812: When a multiprocessing Process child raises an exception,