Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d52aa31

Browse files
authored
bpo-30418: Popen.communicate() always ignore EINVAL (#2002)
On Windows, subprocess.Popen.communicate() now also ignore EINVAL on stdin.write() if the child process is still running but closed the pipe.
1 parent 64505a1 commit d52aa31

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
@@ -778,19 +778,21 @@ def _stdin_write(self, input):
778778
self.stdin.write(input)
779779
except BrokenPipeError:
780780
pass # communicate() must ignore broken pipe errors.
781-
except OSError as e:
782-
if e.errno == errno.EINVAL and self.poll() is not None:
783-
# Issue #19612: On Windows, stdin.write() fails with EINVAL
784-
# if the process already exited before the write
781+
except OSError as exc:
782+
if exc.errno == errno.EINVAL:
783+
# bpo-19612, bpo-30418: On Windows, stdin.write() fails
784+
# with EINVAL if the child process exited or if the child
785+
# process is still running but closed the pipe.
785786
pass
786787
else:
787788
raise
789+
788790
try:
789791
self.stdin.close()
790792
except BrokenPipeError:
791793
pass # communicate() must ignore broken pipe errors.
792-
except OSError as e:
793-
if e.errno == errno.EINVAL and self.poll() is not None:
794+
except OSError as exc:
795+
if exc.errno == errno.EINVAL:
794796
pass
795797
else:
796798
raise

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ Extension Modules
350350
Library
351351
-------
352352

353+
- bpo-30418: On Windows, subprocess.Popen.communicate() now also ignore EINVAL
354+
on stdin.write() if the child process is still running but closed the pipe.
355+
353356
- bpo-30463: Addded empty __slots__ to abc.ABC. This allows subclassers
354357
to deny __dict__ and __weakref__ creation. Patch by Aaron Hall.
355358

0 commit comments

Comments
 (0)