summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-05-21 02:20:36 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-05-21 02:20:36 +0200
commit9904b22b78624174f1e0d06b7e2aed019bfeb550 (patch)
tree14c34cfb3644ae5a1d1112bcbf67d3398396d9e3
parent32565b6c02e9673f9f9368f233e862dfc8a702c9 (diff)
downloadcpython-git-9904b22b78624174f1e0d06b7e2aed019bfeb550.tar.gz
Close #12114: fix a potential deadlock in packaging.util._find_exe_version()
Avoid also zombi processes: Popen.communicate() calls its wait() method.
-rw-r--r--Lib/packaging/tests/test_util.py3
-rw-r--r--Lib/packaging/util.py2
2 files changed, 4 insertions, 1 deletions
diff --git a/Lib/packaging/tests/test_util.py b/Lib/packaging/tests/test_util.py
index 4beab0fe5a..53f6a56319 100644
--- a/Lib/packaging/tests/test_util.py
+++ b/Lib/packaging/tests/test_util.py
@@ -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,
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
index 71ce819af0..bf31c31be6 100644
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -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()