From 684799a0ba676512bfd81a7cbd97e93be4da008a Mon Sep 17 00:00:00 2001 From: Adam Ling Date: Wed, 24 May 2023 17:01:53 -0700 Subject: [PATCH] close tmp file handle --- src/snowflake/connector/cache.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/snowflake/connector/cache.py b/src/snowflake/connector/cache.py index b15ae132b..6415e34bd 100644 --- a/src/snowflake/connector/cache.py +++ b/src/snowflake/connector/cache.py @@ -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(