[Python-checkins] cpython (merge 3.2 -> default): Issue #13812: When a multiprocessing Process child raises an exception, flush
antoine.pitrou
python-checkins at python.org
Fri Jan 27 10:58:03 CET 2012
http://hg.python.org/cpython/rev/96c1de5acbd3
changeset: 74653:96c1de5acbd3
parent: 74651:849e113ddf83
parent: 74652:2863d9273abd
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri Jan 27 10:53:35 2012 +0100
summary:
Issue #13812: When a multiprocessing Process child raises an exception, flush stderr after printing the exception traceback.
files:
Lib/multiprocessing/forking.py | 2 -
Lib/multiprocessing/process.py | 7 +++--
Lib/test/test_multiprocessing.py | 23 ++++++++++++++++++++
Misc/NEWS | 3 ++
4 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py
--- a/Lib/multiprocessing/forking.py
+++ b/Lib/multiprocessing/forking.py
@@ -129,8 +129,6 @@
import random
random.seed()
code = process_obj._bootstrap()
- sys.stdout.flush()
- sys.stderr.flush()
os._exit(code)
# `w` will be closed when the child exits, at which point `r`
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py
--- a/Lib/multiprocessing/process.py
+++ b/Lib/multiprocessing/process.py
@@ -291,16 +291,17 @@
exitcode = e.args[0]
else:
sys.stderr.write(e.args[0] + '\n')
- sys.stderr.flush()
exitcode = 1
except:
exitcode = 1
import traceback
sys.stderr.write('Process %s:\n' % self.name)
+ traceback.print_exc()
+ finally:
+ util.info('process exiting with exitcode %d' % exitcode)
+ sys.stdout.flush()
sys.stderr.flush()
- traceback.print_exc()
- util.info('process exiting with exitcode %d' % exitcode)
return exitcode
#
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -417,6 +417,29 @@
uppercaser.stop()
uppercaser.join()
+ def test_stderr_flush(self):
+ # sys.stderr is flushed at process shutdown (issue #13812)
+ if self.TYPE == "threads":
+ return
+
+ testfn = test.support.TESTFN
+ self.addCleanup(test.support.unlink, testfn)
+ proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
+ proc.start()
+ proc.join()
+ with open(testfn, 'r') as f:
+ err = f.read()
+ # The whole traceback was printed
+ self.assertIn("ZeroDivisionError", err)
+ self.assertIn("test_multiprocessing.py", err)
+ self.assertIn("1/0 # MARKER", err)
+
+ @classmethod
+ def _test_stderr_flush(cls, testfn):
+ sys.stderr = open(testfn, 'w')
+ 1/0 # MARKER
+
+
#
#
#
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -461,6 +461,9 @@
Library
-------
+- Issue #13812: When a multiprocessing Process child raises an exception,
+ flush stderr after printing the exception traceback.
+
- Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC
IV attack countermeasure.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list