diff options
author | Peter Astrand <astrand@lysator.liu.se> | 2007-01-07 14:34:16 (GMT) |
---|---|---|
committer | Peter Astrand <astrand@lysator.liu.se> | 2007-01-07 14:34:16 (GMT) |
commit | 1812f8cf3f47659a49712a3e2d633e82d1f09915 (patch) | |
tree | 2b8c1ddb9f3ed98f80168fffe38f0b6cd4f4779a /Lib/subprocess.py | |
parent | ec05a2d5803db2e9d38e1126b8b88062b9e11ce8 (diff) | |
download | cpython-1812f8cf3f47659a49712a3e2d633e82d1f09915.zip cpython-1812f8cf3f47659a49712a3e2d633e82d1f09915.tar.gz cpython-1812f8cf3f47659a49712a3e2d633e82d1f09915.tar.bz2 |
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index abd790d..ea1e0d1 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1111,6 +1111,7 @@ class Popen(object): read_set.append(self.stderr) stderr = [] + input_offset = 0 while read_set or write_set: rlist, wlist, xlist = select.select(read_set, write_set, []) @@ -1118,9 +1119,9 @@ class Popen(object): # When select has indicated that the file is writable, # we can write up to PIPE_BUF bytes without risk # blocking. POSIX defines PIPE_BUF >= 512 - bytes_written = os.write(self.stdin.fileno(), input[:512]) - input = input[bytes_written:] - if not input: + bytes_written = os.write(self.stdin.fileno(), buffer(input, input_offset, 512)) + input_offset += bytes_written + if input_offset >= len(input): self.stdin.close() write_set.remove(self.stdin) |