From aa2519de5bf0b3b383db2c31eacbf8ac4328e19c Mon Sep 17 00:00:00 2001 From: Mohammed Rafi KC Date: Tue, 9 May 2023 03:29:34 +0530 Subject: [PATCH] windows: Fix open fd error on windows Unlike linux, windows will not allow a rename to happen if there is an open fd. Hence, closing the fd's before renaming Signed-off-by: Mohammed Rafi KC --- sync_files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sync_files.py b/sync_files.py index ff559e3..ce0b707 100644 --- a/sync_files.py +++ b/sync_files.py @@ -27,7 +27,7 @@ def write_sync_file(fpath, contents): sgf.write(contents) sgf.flush() os.fsync(sgf.fileno()) # file should close when you exit block - os.rename(fpath + notyet, fpath) + os.rename(fpath + notyet, fpath) def write_pickle(fpath, obj): @@ -35,7 +35,7 @@ def write_pickle(fpath, obj): pickle.dump(obj, result_file) result_file.flush() os.fsync(result_file.fileno()) # or else reader may not see data - os.rename(fpath + notyet, fpath) + os.rename(fpath + notyet, fpath) # create directory if it's not already there