summaryrefslogtreecommitdiff
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2016-06-04 00:22:17 +0000
committerGregory P. Smith <greg@krypto.org>2016-06-04 00:22:17 +0000
commit9e805f268147672224777837447d41d05aa3a0b7 (patch)
tree42cee4fee9300c0a663ca32b28b5fa398b4f2c4e /Lib/subprocess.py
parent821616cab0ab809da790bcebb2817509cd9beab1 (diff)
downloadcpython-9e805f268147672224777837447d41d05aa3a0b7.tar.gz
Fixes Issue #26373: subprocess.Popen.communicate now correctly ignores
BrokenPipeError when the child process dies before .communicate() is called in more (all?) circumstances.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 4d316e6226..d8d6ab2274 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1011,8 +1011,7 @@ class Popen(object):
try:
self.stdin.write(input)
except BrokenPipeError:
- # communicate() must ignore broken pipe error
- pass
+ pass # communicate() must ignore broken pipe errors.
except OSError as e:
if e.errno == errno.EINVAL and self.poll() is not None:
# Issue #19612: On Windows, stdin.write() fails with EINVAL
@@ -1020,7 +1019,15 @@ class Popen(object):
pass
else:
raise
- self.stdin.close()
+ try:
+ self.stdin.close()
+ except BrokenPipeError:
+ pass # communicate() must ignore broken pipe errors.
+ except OSError as e:
+ if e.errno == errno.EINVAL and self.poll() is not None:
+ pass
+ else:
+ raise
def communicate(self, input=None, timeout=None):
"""Interact with process: Send data to stdin. Read data from
@@ -1661,9 +1668,15 @@ class Popen(object):
if self.stdin and not self._communication_started:
# Flush stdio buffer. This might block, if the user has
# been writing to .stdin in an uncontrolled fashion.
- self.stdin.flush()
+ try:
+ self.stdin.flush()
+ except BrokenPipeError:
+ pass # communicate() must ignore BrokenPipeError.
if not input:
- self.stdin.close()
+ try:
+ self.stdin.close()
+ except BrokenPipeError:
+ pass # communicate() must ignore BrokenPipeError.
stdout = None
stderr = None