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

Slightly safer cleanup of temporary file

Ensure file descriptor is closed before trying to remove the temporary file, as otherwise I suspect the removal might fail on some operating systems. I think such a situation might happen only very rarely though (maybe if disk is full?).
上级 8be2bc23
...@@ -68,6 +68,7 @@ int main( int argc, const char* argv[] ) ...@@ -68,6 +68,7 @@ int main( int argc, const char* argv[] )
try: try:
os.write(fd, code) os.write(fd, code)
os.close(fd) os.close(fd)
fd = None
proc = subprocess.Popen(['g++', '-fopenmp', path], proc = subprocess.Popen(['g++', '-fopenmp', path],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
...@@ -76,7 +77,12 @@ int main( int argc, const char* argv[] ) ...@@ -76,7 +77,12 @@ int main( int argc, const char* argv[] )
if proc.returncode != 0: if proc.returncode != 0:
default_openmp = False default_openmp = False
finally: finally:
os.remove(path) # Ensure `fd` is closed before we remove the temporary file.
try:
if fd is not None:
os.close(fd)
finally:
os.remove(path)
except OSError, e: except OSError, e:
default_openmp = False default_openmp = False
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论