]> granicus.if.org Git - python/commitdiff
Also close file descriptors from os.popen and subprocess.Popen
authorÉric Araujo <merwok@netwok.org>
Sat, 6 Nov 2010 02:10:32 +0000 (02:10 +0000)
committerÉric Araujo <merwok@netwok.org>
Sat, 6 Nov 2010 02:10:32 +0000 (02:10 +0000)
Lib/distutils/command/bdist_rpm.py
Lib/distutils/msvc9compiler.py

index 452f9502ad817e6f69d103919aaf2e6498dd615f..e2ae877d9a3c7237ffd904314f0aa94c8dd5c65d 100644 (file)
@@ -343,22 +343,26 @@ class bdist_rpm(Command):
             src_rpm, non_src_rpm, spec_path)
 
         out = os.popen(q_cmd)
-        binary_rpms = []
-        source_rpm = None
-        while True:
-            line = out.readline()
-            if not line:
-                break
-            l = line.strip().split()
-            assert(len(l) == 2)
-            binary_rpms.append(l[1])
-            # The source rpm is named after the first entry in the spec file
-            if source_rpm is None:
-                source_rpm = l[0]
-
-        status = out.close()
-        if status:
-            raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
+        try:
+            binary_rpms = []
+            source_rpm = None
+            while True:
+                line = out.readline()
+                if not line:
+                    break
+                l = line.strip().split()
+                assert(len(l) == 2)
+                binary_rpms.append(l[1])
+                # The source rpm is named after the first entry in the spec file
+                if source_rpm is None:
+                    source_rpm = l[0]
+
+            status = out.close()
+            if status:
+                raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
+
+        finally:
+            out.close()
 
         self.spawn(rpm_cmd)
 
index 761b9ca236b185da55a991ac63be8198324b6a11..6d7825df86ea32e7f814f40ae65710185cf28102 100644 (file)
@@ -263,10 +263,12 @@ def query_vcvarsall(version, arch="x86"):
     popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
-
-    stdout, stderr = popen.communicate()
-    if popen.wait() != 0:
-        raise DistutilsPlatformError(stderr.decode("mbcs"))
+    try:
+        stdout, stderr = popen.communicate()
+        if popen.wait() != 0:
+            raise DistutilsPlatformError(stderr.decode("mbcs"))
+    finally:
+        popen.close()
 
     stdout = stdout.decode("mbcs")
     for line in stdout.split("\n"):