bpo-30418: Popen.communicate() always ignore EINVAL (#2002) (#2004)

On Windows, subprocess.Popen.communicate() now also ignore EINVAL
on stdin.write() if the child process is still running but closed the
pipe.
(cherry picked from commit d52aa31378)
This commit is contained in:
Victor Stinner 2017-06-08 23:14:07 +02:00 committed by GitHub
parent 31b950ab86
commit b319d09ee4
2 changed files with 11 additions and 6 deletions

View file

@ -776,19 +776,21 @@ class Popen(object):
self.stdin.write(input) self.stdin.write(input)
except BrokenPipeError: except BrokenPipeError:
pass # communicate() must ignore broken pipe errors. pass # communicate() must ignore broken pipe errors.
except OSError as e: except OSError as exc:
if e.errno == errno.EINVAL and self.poll() is not None: if exc.errno == errno.EINVAL:
# Issue #19612: On Windows, stdin.write() fails with EINVAL # bpo-19612, bpo-30418: On Windows, stdin.write() fails
# if the process already exited before the write # with EINVAL if the child process exited or if the child
# process is still running but closed the pipe.
pass pass
else: else:
raise raise
try: try:
self.stdin.close() self.stdin.close()
except BrokenPipeError: except BrokenPipeError:
pass # communicate() must ignore broken pipe errors. pass # communicate() must ignore broken pipe errors.
except OSError as e: except OSError as exc:
if e.errno == errno.EINVAL and self.poll() is not None: if exc.errno == errno.EINVAL:
pass pass
else: else:
raise raise

View file

@ -45,6 +45,9 @@ Core and Builtins
Library Library
------- -------
- bpo-30418: On Windows, subprocess.Popen.communicate() now also ignore EINVAL
on stdin.write() if the child process is still running but closed the pipe.
- bpo-29822: inspect.isabstract() now works during __init_subclass__. Patch - bpo-29822: inspect.isabstract() now works during __init_subclass__. Patch
by Nate Soares. by Nate Soares.