[Python-checkins] r53513 - in python/branches/release25-maint: Lib/subprocess.py Misc/NEWS

peter.astrand python-checkins at python.org
Sun Jan 21 16:45:25 CET 2007


Author: peter.astrand
Date: Sun Jan 21 16:45:25 2007
New Revision: 53513

Modified:
   python/branches/release25-maint/Lib/subprocess.py
   python/branches/release25-maint/Misc/NEWS
Log:
Avoid O(N**2) bottleneck in _communicate_(). Fixes #1598181. Backport from rev. 53295.

Modified: python/branches/release25-maint/Lib/subprocess.py
==============================================================================
--- python/branches/release25-maint/Lib/subprocess.py	(original)
+++ python/branches/release25-maint/Lib/subprocess.py	Sun Jan 21 16:45:25 2007
@@ -1111,6 +1111,7 @@
                 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 @@
                     # 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)
 

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Sun Jan 21 16:45:25 2007
@@ -143,6 +143,8 @@
 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.


More information about the Python-checkins mailing list