Skip to content

Commit b319d09

Browse files
authored
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 d52aa31)
1 parent 31b950a commit b319d09

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Lib/subprocess.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -776,19 +776,21 @@ def _stdin_write(self, input):
776776
self.stdin.write(input)
777777
except BrokenPipeError:
778778
pass # communicate() must ignore broken pipe errors.
779-
except OSError as e:
780-
if e.errno == errno.EINVAL and self.poll() is not None:
781-
# Issue #19612: On Windows, stdin.write() fails with EINVAL
782-
# if the process already exited before the write
779+
except OSError as exc:
780+
if exc.errno == errno.EINVAL:
781+
# bpo-19612, bpo-30418: On Windows, stdin.write() fails
782+
# with EINVAL if the child process exited or if the child
783+
# process is still running but closed the pipe.
783784
pass
784785
else:
785786
raise
787+
786788
try:
787789
self.stdin.close()
788790
except BrokenPipeError:
789791
pass # communicate() must ignore broken pipe errors.
790-
except OSError as e:
791-
if e.errno == errno.EINVAL and self.poll() is not None:
792+
except OSError as exc:
793+
if exc.errno == errno.EINVAL:
792794
pass
793795
else:
794796
raise

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Core and Builtins
4545
Library
4646
-------
4747

48+
- bpo-30418: On Windows, subprocess.Popen.communicate() now also ignore EINVAL
49+
on stdin.write() if the child process is still running but closed the pipe.
50+
4851
- bpo-29822: inspect.isabstract() now works during __init_subclass__. Patch
4952
by Nate Soares.
5053

0 commit comments

Comments
 (0)