mirror of
https://github.com/python/cpython.git
synced 2024-11-28 20:33:54 +08:00
Also close file descriptors from os.popen and subprocess.Popen
This commit is contained in:
parent
25b5741383
commit
5ac6d80c02
@ -343,22 +343,26 @@ class bdist_rpm(Command):
|
|||||||
src_rpm, non_src_rpm, spec_path)
|
src_rpm, non_src_rpm, spec_path)
|
||||||
|
|
||||||
out = os.popen(q_cmd)
|
out = os.popen(q_cmd)
|
||||||
binary_rpms = []
|
try:
|
||||||
source_rpm = None
|
binary_rpms = []
|
||||||
while True:
|
source_rpm = None
|
||||||
line = out.readline()
|
while True:
|
||||||
if not line:
|
line = out.readline()
|
||||||
break
|
if not line:
|
||||||
l = line.strip().split()
|
break
|
||||||
assert(len(l) == 2)
|
l = line.strip().split()
|
||||||
binary_rpms.append(l[1])
|
assert(len(l) == 2)
|
||||||
# The source rpm is named after the first entry in the spec file
|
binary_rpms.append(l[1])
|
||||||
if source_rpm is None:
|
# The source rpm is named after the first entry in the spec file
|
||||||
source_rpm = l[0]
|
if source_rpm is None:
|
||||||
|
source_rpm = l[0]
|
||||||
|
|
||||||
status = out.close()
|
status = out.close()
|
||||||
if status:
|
if status:
|
||||||
raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
|
raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
|
||||||
|
|
||||||
|
finally:
|
||||||
|
out.close()
|
||||||
|
|
||||||
self.spawn(rpm_cmd)
|
self.spawn(rpm_cmd)
|
||||||
|
|
||||||
|
@ -263,10 +263,12 @@ def query_vcvarsall(version, arch="x86"):
|
|||||||
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
|
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
|
try:
|
||||||
stdout, stderr = popen.communicate()
|
stdout, stderr = popen.communicate()
|
||||||
if popen.wait() != 0:
|
if popen.wait() != 0:
|
||||||
raise DistutilsPlatformError(stderr.decode("mbcs"))
|
raise DistutilsPlatformError(stderr.decode("mbcs"))
|
||||||
|
finally:
|
||||||
|
popen.close()
|
||||||
|
|
||||||
stdout = stdout.decode("mbcs")
|
stdout = stdout.decode("mbcs")
|
||||||
for line in stdout.split("\n"):
|
for line in stdout.split("\n"):
|
||||||
|
Loading…
Reference in New Issue
Block a user