diff options
author | Antoine Pitrou <pitrou@free.fr> | 2018-03-11 19:09:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-11 19:09:20 (GMT) |
commit | 069b8d20be8018fbd49ed5aaf64c4caba311e48f (patch) | |
tree | 7b6d73f84bde5b2ce5fecd0d3ae4e8edcd075ba3 /Lib/test | |
parent | 20ac11a9fb027f183914bbaaaed091b57c882e54 (diff) | |
download | cpython-069b8d20be8018fbd49ed5aaf64c4caba311e48f.zip cpython-069b8d20be8018fbd49ed5aaf64c4caba311e48f.tar.gz cpython-069b8d20be8018fbd49ed5aaf64c4caba311e48f.tar.bz2 |
[3.6] bpo-31804: Fix multiprocessing.Process with broken standard streams (GH-6079) (GH-6081)
In some conditions the standard streams will be None or closed in the child process (for example if using "pythonw" instead of "python" on Windows). Avoid failing with a non-0 exit code in those conditions.
Report and initial patch by poxthegreat..
(cherry picked from commit e756f66c83786ee82f5f7d45931ae50a6931dd7f)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index e4d60f8..dd0a9d7 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -427,10 +427,19 @@ class _TestProcess(BaseTestCase): close_queue(q) @classmethod - def _test_error_on_stdio_flush(self, evt): + def _test_error_on_stdio_flush(self, evt, break_std_streams={}): + for stream_name, action in break_std_streams.items(): + if action == 'close': + stream = io.StringIO() + stream.close() + else: + assert action == 'remove' + stream = None + setattr(sys, stream_name, None) evt.set() - def test_error_on_stdio_flush(self): + def test_error_on_stdio_flush_1(self): + # Check that Process works with broken standard streams streams = [io.StringIO(), None] streams[0].close() for stream_name in ('stdout', 'stderr'): @@ -444,6 +453,24 @@ class _TestProcess(BaseTestCase): proc.start() proc.join() self.assertTrue(evt.is_set()) + self.assertEqual(proc.exitcode, 0) + finally: + setattr(sys, stream_name, old_stream) + + def test_error_on_stdio_flush_2(self): + # Same as test_error_on_stdio_flush_1(), but standard streams are + # broken by the child process + for stream_name in ('stdout', 'stderr'): + for action in ('close', 'remove'): + old_stream = getattr(sys, stream_name) + try: + evt = self.Event() + proc = self.Process(target=self._test_error_on_stdio_flush, + args=(evt, {stream_name: action})) + proc.start() + proc.join() + self.assertTrue(evt.is_set()) + self.assertEqual(proc.exitcode, 0) finally: setattr(sys, stream_name, old_stream) |