Commit 84a0fbf6 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #13812: When a multiprocessing Process child raises an exception, flush...

Issue #13812: When a multiprocessing Process child raises an exception, flush stderr after printing the exception traceback.
parent 9f6b02ec
...@@ -124,8 +124,6 @@ if sys.platform != 'win32': ...@@ -124,8 +124,6 @@ if sys.platform != 'win32':
import random import random
random.seed() random.seed()
code = process_obj._bootstrap() code = process_obj._bootstrap()
sys.stdout.flush()
sys.stderr.flush()
os._exit(code) os._exit(code)
def poll(self, flag=os.WNOHANG): def poll(self, flag=os.WNOHANG):
......
...@@ -275,16 +275,17 @@ class Process(object): ...@@ -275,16 +275,17 @@ class Process(object):
exitcode = e.args[0] exitcode = e.args[0]
else: else:
sys.stderr.write(e.args[0] + '\n') sys.stderr.write(e.args[0] + '\n')
sys.stderr.flush()
exitcode = 1 exitcode = 1
except: except:
exitcode = 1 exitcode = 1
import traceback import traceback
sys.stderr.write('Process %s:\n' % self.name) sys.stderr.write('Process %s:\n' % self.name)
sys.stderr.flush()
traceback.print_exc() traceback.print_exc()
finally:
util.info('process exiting with exitcode %d' % exitcode) util.info('process exiting with exitcode %d' % exitcode)
sys.stdout.flush()
sys.stderr.flush()
return exitcode return exitcode
# #
......
...@@ -367,6 +367,29 @@ class _TestSubclassingProcess(BaseTestCase): ...@@ -367,6 +367,29 @@ class _TestSubclassingProcess(BaseTestCase):
uppercaser.stop() uppercaser.stop()
uppercaser.join() 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
# #
# #
# #
......
...@@ -111,6 +111,9 @@ Core and Builtins ...@@ -111,6 +111,9 @@ Core and Builtins
Library 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 - Issue #13885: CVE-2011-3389: the _ssl module would always disable the CBC
IV attack countermeasure. IV attack countermeasure.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment