From bb7dd7b64668d4b645dba38a3bc52be452d14eb8 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Tue, 22 Aug 2023 17:45:38 +0300 Subject: [PATCH] use an atomic operation to replace the cache with the new version --- modules/cache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/cache.py b/modules/cache.py index a7cd3aebc..ff26a2132 100644 --- a/modules/cache.py +++ b/modules/cache.py @@ -30,9 +30,12 @@ def dump_cache(): time.sleep(1) with cache_lock: - with open(cache_filename, "w", encoding="utf8") as file: + cache_filename_tmp = cache_filename + "-" + with open(cache_filename_tmp, "w", encoding="utf8") as file: json.dump(cache_data, file, indent=4) + os.replace(cache_filename_tmp, cache_filename) + dump_cache_after = None dump_cache_thread = None