Skip to content

Commit df04c08

Browse files
authored
bpo-30418: Popen.communicate() always ignore EINVAL (#2002) (#2005)
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 a0b9088 commit df04c08

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
@@ -741,19 +741,21 @@ def _stdin_write(self, input):
741741
self.stdin.write(input)
742742
except BrokenPipeError:
743743
pass # communicate() must ignore broken pipe errors.
744-
except OSError as e:
745-
if e.errno == errno.EINVAL and self.poll() is not None:
746-
# Issue #19612: On Windows, stdin.write() fails with EINVAL
747-
# if the process already exited before the write
744+
except OSError as exc:
745+
if exc.errno == errno.EINVAL:
746+
# bpo-19612, bpo-30418: On Windows, stdin.write() fails
747+
# with EINVAL if the child process exited or if the child
748+
# process is still running but closed the pipe.
748749
pass
749750
else:
750751
raise
752+
751753
try:
752754
self.stdin.close()
753755
except BrokenPipeError:
754756
pass # communicate() must ignore broken pipe errors.
755-
except OSError as e:
756-
if e.errno == errno.EINVAL and self.poll() is not None:
757+
except OSError as exc:
758+
if exc.errno == errno.EINVAL:
757759
pass
758760
else:
759761
raise

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ Extension Modules
5656
Library
5757
-------
5858

59+
- bpo-30418: On Windows, subprocess.Popen.communicate() now also ignore EINVAL
60+
on stdin.write() if the child process is still running but closed the pipe.
61+
5962
- bpo-30378: Fix the problem that logging.handlers.SysLogHandler cannot
6063
handle IPv6 addresses.
6164

0 commit comments

Comments
 (0)