Skip to content

Commit

Permalink
close tmp file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-aling committed May 25, 2023
1 parent 36e20a0 commit 684799a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/snowflake/connector/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,10 @@ def _save(self, load_first: bool = True) -> bool:
prefix=fname,
dir=_dir,
)
with open(tmp_file, "wb") as w_file:
pickle.dump(self, w_file)
os.write(tmp_file, pickle.dumps(self))
os.close(
tmp_file
) # tmp_file is already an open handle, we close it after writing
# We write to a tmp file and then move it to have atomic write
os.replace(tmp_file_path, self.file_path)
self.last_loaded = datetime.datetime.fromtimestamp(
Expand Down

0 comments on commit 684799a

Please sign in to comment.