提交 6e7018b6 authored 作者: Frederic's avatar Frederic

Always use stdin=devnull when calling Popen.

上级 fc732bc6
......@@ -1481,11 +1481,9 @@ def gcc_llvm():
"""
if gcc_llvm.is_llvm is None:
pass
dummy_in = open(os.devnull)
p = None
try:
p = call_subprocess_Popen(['g++', '--version'],
stdin=dummy_in.fileno(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.wait()
......@@ -1499,7 +1497,6 @@ def gcc_llvm():
# will crash later so supposing it is not llvm is "safe".
output = ''
del p
del dummy_in
gcc_llvm.is_llvm = "llvm" in output
return gcc_llvm.is_llvm
gcc_llvm.is_llvm = None
......@@ -1546,16 +1543,11 @@ class GCC_compiler(object):
GCC_compiler.march_flags = []
def get_lines(cmd, parse=True):
dummy_in = open(os.devnull)
try:
p = call_subprocess_Popen(cmd,
stdin=dummy_in.fileno(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
p.wait()
finally:
del dummy_in
stdout = p.stdout.readlines()
stderr = p.stderr.readlines()
lines = []
......@@ -1650,7 +1642,6 @@ class GCC_compiler(object):
try:
fd, path = tempfile.mkstemp(suffix='.c', prefix=tmp_prefix)
exe_path = path[:-2]
dummy_stdin = open(os.devnull)
try:
os.write(fd, src_code)
os.close(fd)
......@@ -1658,8 +1649,7 @@ class GCC_compiler(object):
proc = call_subprocess_Popen(
['g++', path, '-o', exe_path] + flags,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
stderr=subprocess.PIPE)
proc.wait()
if proc.returncode != 0:
compilation_ok = False
......@@ -1669,14 +1659,12 @@ class GCC_compiler(object):
try:
proc = call_subprocess_Popen([exe_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
stderr=subprocess.PIPE)
proc.wait()
run_ok = (proc.returncode == 0)
finally:
os.remove(exe_path)
finally:
del dummy_stdin
try:
if fd is not None:
os.close(fd)
......
......@@ -18,13 +18,11 @@ from theano.misc.windows import call_subprocess_Popen
# Using the dummy file descriptors below is a workaround for a crash
# experienced in an unusual Python 2.4.4 Windows environment with the default
# None values.
dummy_in = open(os.devnull)
dummy_err = open(os.devnull, 'w')
p = None
try:
p = call_subprocess_Popen(['g++', '-dumpversion'],
stdout=subprocess.PIPE,
stdin=dummy_in.fileno(),
stderr=dummy_err.fileno())
p.wait()
gcc_version_str = p.stdout.readline().strip().decode()
......@@ -32,7 +30,6 @@ except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
del p
del dummy_in
del dummy_err
compiledir_format_dict = {"platform": platform.platform(),
......
......@@ -21,5 +21,18 @@ def call_subprocess_Popen(command, **params):
# execute "g++" without extensions.
# (Executing "g++.bat" explicitly would also work.)
params['shell'] = True
# Using the dummy file descriptors below is a workaround for a
# crash experienced in an unusual Python 2.4.4 Windows environment
# with the default None values.
stdin = None
if "stdin" not in params:
stdin = open(os.devnull)
params['stdin'] = stdin.fileno()
try:
proc = subprocess.Popen(command, startupinfo=startupinfo, **params)
finally:
if stdin is not None:
del stdin
return proc
......@@ -276,8 +276,7 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
# test name in display
# (see class 'DisabDocString' in file theano-nose)
stderr=subprocess.PIPE,
stdout=dummy_out.fileno(),
stdin=dummy_in.fileno())
stdout=dummy_out.fileno())
# recovering and processing data from pipe
err = proc.stderr.read()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论