提交 a8937a8a authored 作者: Olivier Delalleau's avatar Olivier Delalleau

A few bugfixes:

- Fixed crashes in an unusual Python 2.4.4 Windows environment when calling subprocess.Popen with a mix of PIPE and None values for stdout, stderr and stdin. - Fixed crashes when using a C cache copied from another location.
上级 e0fd6770
...@@ -74,9 +74,13 @@ AddConfigVar('mode', ...@@ -74,9 +74,13 @@ AddConfigVar('mode',
'FAST_COMPILE', 'PROFILE_MODE', 'DEBUG_MODE'), 'FAST_COMPILE', 'PROFILE_MODE', 'DEBUG_MODE'),
in_c_key=False) in_c_key=False)
# Test whether or not gcc is present: disable C code if it is not # Test whether or not gcc is present: disable C code if it is not.
# Using the dummy file descriptor below is a workaround for a crash experienced
# in an unusual Python 2.4.4 Windows environment with the default stdin=None.
dummy_stdin = open(os.devnull)
try: try:
subprocess.Popen('gcc', stdout=subprocess.PIPE, stderr=subprocess.PIPE) subprocess.Popen('gcc', stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=dummy_stdin.fileno())
# Keep the default linker the same as the one for the mode FAST_RUN # Keep the default linker the same as the one for the mode FAST_RUN
AddConfigVar('linker', AddConfigVar('linker',
"Default linker used if the theano flags mode is Mode or ProfileMode", "Default linker used if the theano flags mode is Mode or ProfileMode",
...@@ -92,6 +96,8 @@ except OSError: ...@@ -92,6 +96,8 @@ except OSError:
'C-implementations (for both CPU and GPU) and will default to '+ 'C-implementations (for both CPU and GPU) and will default to '+
'Python implementations. Performance will be severely degraded.') 'Python implementations. Performance will be severely degraded.')
del dummy_stdin
#Keep the default optimizer the same as the one for the mode FAST_RUN #Keep the default optimizer the same as the one for the mode FAST_RUN
AddConfigVar('optimizer', AddConfigVar('optimizer',
"Default optimizer. If not None, will use this linker with the Mode object(not ProfileMode or DebugMode)", "Default optimizer. If not None, will use this linker with the Mode object(not ProfileMode or DebugMode)",
......
...@@ -224,7 +224,7 @@ def is_same_entry(entry_1, entry_2): ...@@ -224,7 +224,7 @@ def is_same_entry(entry_1, entry_2):
This is the case if and only if at least one of these conditions holds: This is the case if and only if at least one of these conditions holds:
- They are equal. - They are equal.
- There real paths are equal. - Their real paths are equal.
- They share the same temporary work directory and module file name. - They share the same temporary work directory and module file name.
""" """
if entry_1 == entry_2: if entry_1 == entry_2:
...@@ -234,7 +234,7 @@ def is_same_entry(entry_1, entry_2): ...@@ -234,7 +234,7 @@ def is_same_entry(entry_1, entry_2):
if (os.path.basename(entry_1) == os.path.basename(entry_2) and if (os.path.basename(entry_1) == os.path.basename(entry_2) and
(os.path.basename(os.path.dirname(entry_1)) == (os.path.basename(os.path.dirname(entry_1)) ==
os.path.basename(os.path.dirname(entry_2))) and os.path.basename(os.path.dirname(entry_2))) and
os.path.basename(os.path.dirname(entry_1).startswith('tmp'))): os.path.basename(os.path.dirname(entry_1)).startswith('tmp')):
return True return True
return False return False
...@@ -594,8 +594,12 @@ class ModuleCache(object): ...@@ -594,8 +594,12 @@ class ModuleCache(object):
kd_entry = key_data.get_entry() kd_entry = key_data.get_entry()
if kd_entry != entry: if kd_entry != entry:
if is_same_entry(entry, kd_entry): if is_same_entry(entry, kd_entry):
# Update KeyData object. # Update KeyData object. Note that we also need
# to update the key_pkl field, because it is
# likely to be incorrect if the entry itself
# was wrong.
key_data.entry = entry key_data.entry = entry
key_data.key_pkl = key_pkl
else: else:
# This is suspicious. Better get rid of it. # This is suspicious. Better get rid of it.
_rmtree(root, ignore_nocleanup=True, _rmtree(root, ignore_nocleanup=True,
...@@ -1248,10 +1252,22 @@ def std_libs(): ...@@ -1248,10 +1252,22 @@ def std_libs():
def std_lib_dirs(): def std_lib_dirs():
return std_lib_dirs_and_libs()[1] return std_lib_dirs_and_libs()[1]
p=subprocess.Popen(['gcc','-dumpversion'],stdout=subprocess.PIPE) # Using the dummy file descriptors below is a workaround for a crash experienced
p.wait() # in an unusual Python 2.4.4 Windows environment with the default None values.
gcc_version_str = p.stdout.readline().strip() dummy_in = open(os.devnull)
dummy_err = open(os.devnull, 'w')
p = None
try:
p = subprocess.Popen(['gcc', '-dumpversion'], stdout=subprocess.PIPE,
stdin=dummy_in.fileno(), stderr=dummy_err.fileno())
p.wait()
gcc_version_str = p.stdout.readline().strip()
except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
del p del p
del dummy_in
del dummy_err
def gcc_version(): def gcc_version():
return gcc_version_str return gcc_version_str
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论