Commit 1812f8cf authored by Peter Astrand's avatar Peter Astrand

Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181.

parent ec05a2d5
...@@ -1111,6 +1111,7 @@ class Popen(object): ...@@ -1111,6 +1111,7 @@ class Popen(object):
read_set.append(self.stderr) read_set.append(self.stderr)
stderr = [] stderr = []
input_offset = 0
while read_set or write_set: while read_set or write_set:
rlist, wlist, xlist = select.select(read_set, write_set, []) rlist, wlist, xlist = select.select(read_set, write_set, [])
...@@ -1118,9 +1119,9 @@ class Popen(object): ...@@ -1118,9 +1119,9 @@ class Popen(object):
# When select has indicated that the file is writable, # When select has indicated that the file is writable,
# we can write up to PIPE_BUF bytes without risk # we can write up to PIPE_BUF bytes without risk
# blocking. POSIX defines PIPE_BUF >= 512 # blocking. POSIX defines PIPE_BUF >= 512
bytes_written = os.write(self.stdin.fileno(), input[:512]) bytes_written = os.write(self.stdin.fileno(), buffer(input, input_offset, 512))
input = input[bytes_written:] input_offset += bytes_written
if not input: if input_offset >= len(input):
self.stdin.close() self.stdin.close()
write_set.remove(self.stdin) write_set.remove(self.stdin)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment