From 8855a75cc3d1063d9e084a1604912b9937241678 Mon Sep 17 00:00:00 2001 From: OwnerSunshine530 Date: Sun, 14 Jun 2026 22:32:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=93=E5=AD=98=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=86=99+fsync=EF=BC=8C=E5=8E=BB=E6=8E=89=E4=BC=9A=E8=AF=AF?= =?UTF-8?q?=E5=88=A0=E7=9A=84=E5=86=99=E5=90=8E=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 --- 代码/code/bench.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/代码/code/bench.py b/代码/code/bench.py index 201c70b..558e501 100644 --- a/代码/code/bench.py +++ b/代码/code/bench.py @@ -129,23 +129,19 @@ def _save_cache(cache, item_dict, user_seq): 读取会间歇性报 [Errno 38]。pickle.dump 大对象较慢但顺序写更稳。 """ import pickle - tmp = str(cache) + ".tmp" try: - with open(tmp, "wb") as f: + with open(cache, "wb") as f: pickle.dump({"item_dict": item_dict, "user_seq": user_seq}, f, protocol=pickle.HIGHEST_PROTOCOL) f.flush() os.fsync(f.fileno()) - os.replace(tmp, cache) - _load_cache(cache) # 写后立即校验可读 - print(f"[BENCH] 已缓存 -> {cache}") + print(f"[BENCH] 已缓存 -> {cache}(下次秒级读取;读不出会自动重建)") except Exception as e: print(f"[BENCH][WARN] 缓存写入失败({e}),本次不缓存(不影响结果)") - for p in (tmp, str(cache)): - try: - os.remove(p) - except OSError: - pass + try: + os.remove(cache) + except OSError: + pass def _get_data(cur, ref, rebuild=False):