diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-08-14 15:40:21 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-08-14 15:40:21 (GMT) |
commit | aa0dbdc2ddb4cfe1669ac83a24673a8ef4ee1fc4 (patch) | |
tree | 23dbc642b8059bdbc8be3be03b42476be77aa7dd /Lib/subprocess.py | |
parent | f06afe35b9eca02cc99e77c19512841f2d889aef (diff) | |
parent | f3765071eb73ffb3630a64987f7dceddf64be2ea (diff) | |
download | cpython-aa0dbdc2ddb4cfe1669ac83a24673a8ef4ee1fc4.zip cpython-aa0dbdc2ddb4cfe1669ac83a24673a8ef4ee1fc4.tar.gz cpython-aa0dbdc2ddb4cfe1669ac83a24673a8ef4ee1fc4.tar.bz2 |
Issue #15592. Fix regression: subprocess.communicate() breaks on no input with universal newlines true.
Patch by Chris Jerdonek.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 7885ba3..35f6f96 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1536,6 +1536,17 @@ class Popen(object): return (stdout, stderr) + def _save_input(self, input): + # This method is called from the _communicate_with_*() methods + # so that if we time out while communicating, we can continue + # sending input if we retry. + if self.stdin and self._input is None: + self._input_offset = 0 + self._input = input + if self.universal_newlines and input is not None: + self._input = self._input.encode(self.stdin.encoding) + + def _communicate_with_poll(self, input, endtime, orig_timeout): stdout = None # Return stderr = None # Return @@ -1572,13 +1583,7 @@ class Popen(object): register_and_append(self.stderr, select_POLLIN_POLLPRI) stderr = self._fd2output[self.stderr.fileno()] - # Save the input here so that if we time out while communicating, - # we can continue sending input if we retry. - if self.stdin and self._input is None: - self._input_offset = 0 - self._input = input - if self.universal_newlines: - self._input = self._input.encode(self.stdin.encoding) + self._save_input(input) while self._fd2file: timeout = self._remaining_time(endtime) @@ -1632,11 +1637,7 @@ class Popen(object): if self.stderr: self._read_set.append(self.stderr) - if self.stdin and self._input is None: - self._input_offset = 0 - self._input = input - if self.universal_newlines: - self._input = self._input.encode(self.stdin.encoding) + self._save_input(input) stdout = None # Return stderr = None # Return |