]> granicus.if.org Git - python/commitdiff
Close #12114: fix a potential deadlock in packaging.util._find_exe_version()
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 21 May 2011 00:20:36 +0000 (02:20 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 21 May 2011 00:20:36 +0000 (02:20 +0200)
Avoid also zombi processes: Popen.communicate() calls its wait() method.

Lib/packaging/tests/test_util.py
Lib/packaging/util.py

index 4beab0fe5a1e65285388071aa5e47b21ffc22fae..53f6a56319298234b5bf2fb552c93ebb077fa5a5 100644 (file)
@@ -74,6 +74,9 @@ class FakePopen:
             self.stdout = StringIO(exes[self.cmd])
             self.stderr = StringIO()
 
+    def communicate(self, input=None, timeout=None):
+        return self.stdout.read(), self.stderr.read()
+
 
 class UtilTestCase(support.EnvironRestorer,
                    support.TempdirManager,
index 71ce819af015049f324f877c1499c508f8f88eeb..bf31c31be6201e1b61c3be3e84399fda5e7c57b3 100644 (file)
@@ -464,7 +464,7 @@ def _find_exe_version(cmd, pattern=_RE_VERSION):
         return None
     pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
     try:
-        stdout, stderr = pipe.stdout.read(), pipe.stderr.read()
+        stdout, stderr = pipe.communicate()
     finally:
         pipe.stdout.close()
         pipe.stderr.close()