chiark / gitweb /
Work around performance bug in subprocess.Popen.communicate()
authorKarl Wiberg <kha@treskal.com>
Thu, 13 Aug 2009 22:19:24 +0000 (23:19 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Thu, 13 Aug 2009 22:19:24 +0000 (23:19 +0100)
In Python 2.4 (specifically, I tested with 2.4.6 on Ubuntu 9.04),
subprocess.Popen.communicate() seems to take time proportional to the
square of the size of the indata, which makes it ridiculously
expensive to write stack log entries when the diffs are large. Work
around the bug by calling subprocess.Popen.stdin.write() manually
instead of letting communicate() handle the indata.

The performance bug has been fixed in Python 2.6 (I tested with
2.6.2), so with that version this workaround doesn't affect the run
time. I haven't tested with Python 2.5.

This fixes bug 13319.

Signed-off-by: Karl Wiberg <kha@treskal.com>
stgit/run.py

index 7493ed321f094198a36ceb1e225d95bf6b020a5e..2d8ed348b67883f19f050ce89aa8347b417e2e2a 100644 (file)
@@ -110,7 +110,11 @@ class Run:
                                  stdin = subprocess.PIPE,
                                  stdout = subprocess.PIPE,
                                  stderr = subprocess.PIPE)
-            outdata, errdata = p.communicate(self.__indata)
+            # TODO: only use communicate() once support for Python 2.4 is
+            # dropped (write() needed because of performance reasons)
+            if self.__indata:
+                p.stdin.write(self.__indata)
+            outdata, errdata = p.communicate()
             self.exitcode = p.returncode
         except OSError, e:
             raise self.exc('%s failed: %s' % (self.__cmd[0], e))