提交 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[] )
try:
os.write(fd, code)
os.close(fd)
fd = None
proc = subprocess.Popen(['g++', '-fopenmp', path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
......@@ -75,6 +76,11 @@ int main( int argc, const char* argv[] )
proc.wait()
if proc.returncode != 0:
default_openmp = False
finally:
# 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:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论