[Python-checkins] cpython: Close #12114: fix a potential deadlock in packaging.util._find_exe_version()

victor.stinner python-checkins at python.org
Sat May 21 02:22:03 CEST 2011


http://hg.python.org/cpython/rev/bf5b974e7d32
changeset:   70240:bf5b974e7d32
parent:      70238:337477d6aaff
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sat May 21 02:20:36 2011 +0200
summary:
  Close #12114: fix a potential deadlock in packaging.util._find_exe_version()

Avoid also zombi processes: Popen.communicate() calls its wait() method.

files:
  Lib/packaging/tests/test_util.py |  3 +++
  Lib/packaging/util.py            |  2 +-
  2 files changed, 4 insertions(+), 1 deletions(-)


diff --git a/Lib/packaging/tests/test_util.py b/Lib/packaging/tests/test_util.py
--- a/Lib/packaging/tests/test_util.py
+++ b/Lib/packaging/tests/test_util.py
@@ -74,6 +74,9 @@
             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,
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -464,7 +464,7 @@
         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()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list