diff options
author | Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org> | 2016-06-04 00:34:15 (GMT) |
---|---|---|
committer | Gregory P. Smith ext:(%20%5BGoogle%20Inc.%5D) <greg@krypto.org> | 2016-06-04 00:34:15 (GMT) |
commit | fcbf1ca4f9d4701b319aa4b173f27557c3271014 (patch) | |
tree | 0ce1fd69d4d2f528319e7129609f68fecf85844d /Lib/subprocess.py | |
parent | d2367c651ec5e0955d1d27ccec94f060efb246aa (diff) | |
parent | 1ef8c7e886ea5260e5a6967ec2b8a4c32640f1a8 (diff) | |
download | cpython-fcbf1ca4f9d4701b319aa4b173f27557c3271014.zip cpython-fcbf1ca4f9d4701b319aa4b173f27557c3271014.tar.gz cpython-fcbf1ca4f9d4701b319aa4b173f27557c3271014.tar.bz2 |
merge from 3.5 - 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.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 716f7ff..98f339e 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1036,8 +1036,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 @@ -1045,7 +1044,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 @@ -1691,9 +1698,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 |