fileutil.py: use try/finally to close file in write_atomically.

This commit is contained in:
david-sarah 2012-05-16 23:08:39 +00:00
parent 959248cd49
commit 3738c3e2d1

View File

@ -249,8 +249,10 @@ def move_into_place(source, dest):
def write_atomically(target, contents, mode="b"): def write_atomically(target, contents, mode="b"):
f = open(target+".tmp", "w"+mode) f = open(target+".tmp", "w"+mode)
f.write(contents) try:
f.close() f.write(contents)
finally:
f.close()
move_into_place(target+".tmp", target) move_into_place(target+".tmp", target)
def write(path, data): def write(path, data):