From 191ed38f54141ca29d201db8fe0e5558129a1f93 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 3 Aug 2023 12:40:43 +0800 Subject: [PATCH] fix --- app/chain/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/chain/__init__.py b/app/chain/__init__.py index b4745b71..118ec35c 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -39,7 +39,8 @@ class ChainBase(metaclass=ABCMeta): cache_path = settings.TEMP_PATH / filename if cache_path.exists(): try: - return pickle.load(cache_path.open('rb')) + with open(cache_path, 'rb') as f: + return pickle.load(f) except Exception as err: logger.error(f"加载缓存 {filename} 出错:{err}") return None @@ -50,7 +51,8 @@ class ChainBase(metaclass=ABCMeta): 保存缓存到本地 """ try: - pickle.dump(cache, (settings.TEMP_PATH / filename).open('wb')) + with open(settings.TEMP_PATH / filename, 'wb') as f: + pickle.dump(cache, f) except Exception as err: logger.error(f"保存缓存 {filename} 出错:{err}")