bpo-31804: Fix multiprocessing.Process with broken standard streams (GH-6079) (GH-6080)

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 e756f66c83)

Co-authored-by: Antoine Pitrou <pitrou@free.fr>
This commit is contained in:
Miss Islington (bot) 2018-03-11 11:42:37 -07:00 committed by Antoine Pitrou
parent 04aadf23ea
commit ff5d21331e
5 changed files with 47 additions and 12 deletions

View file

@ -14,14 +14,7 @@ class Popen(object):
method = 'fork'
def __init__(self, process_obj):
try:
sys.stdout.flush()
except (AttributeError, ValueError):
pass
try:
sys.stderr.flush()
except (AttributeError, ValueError):
pass
util._flush_std_streams()
self.returncode = None
self.finalizer = None
self._launch(process_obj)