diff options
author | Peter Astrand <astrand@lysator.liu.se> | 2007-01-21 15:45:25 +0000 |
---|---|---|
committer | Peter Astrand <astrand@lysator.liu.se> | 2007-01-21 15:45:25 +0000 |
commit | bb6a0edce1625e41a310cb5980c843eb3cb68f77 (patch) | |
tree | f8eb69187eb4513f015b795890a73508c6f4571e | |
parent | 962e9165aac50703f84f4ea6fd23d81a12fdebeb (diff) | |
download | cpython-git-bb6a0edce1625e41a310cb5980c843eb3cb68f77.tar.gz |
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181. Backport from rev. 53295.
-rw-r--r-- | Lib/subprocess.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index eb1a735671..8b25c2fe85 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) @@ -143,6 +143,8 @@ Extension Modules Library ------- +- Bug #1598181: Avoid O(N**2) bottleneck in subprocess communicate(). + - Patch #1627441: close sockets properly in urllib2. - Bug #1610795: ctypes.util.find_library works now on BSD systems. |