From a409123c9b83e1290647b546c1ade69cdefef29c Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 12 Feb 2014 10:58:04 -0500 Subject: [PATCH] Use a with block to create index.html. Also, updates our IO so we write to a .tmp file and rename it only after the file IO is completed. This wards off a potential race where a user could load a page that hadn't been fully flushed to disk. Change-Id: I04bfb7def801f11e3fcae83272879f660a8d1825 --- reviewday/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reviewday/util.py b/reviewday/util.py index f70477a..33d7d95 100644 --- a/reviewday/util.py +++ b/reviewday/util.py @@ -44,8 +44,8 @@ def create_report(out_dir, name_space={}): prep_out_dir(out_dir) - out_file = open(os.path.join(out_dir, 'index.html'), "w") - out_file.write(str(t)) - out_file.close() + with open(os.path.join(out_dir, 'index.html.tmp'), "w") as f: + f.write(str(t)) + os.rename(f.name, os.path.join(out_dir, 'index.html')) _create_json(out_dir, name_space=name_space)