feat/auc-recovery-plan #1

Merged
Serendipity merged 20 commits from feat/auc-recovery-plan into main 2026-06-15 12:33:32 +08:00
Showing only changes of commit 8855a75cc3 - Show all commits
+3 -7
View File
@@ -129,21 +129,17 @@ def _save_cache(cache, item_dict, user_seq):
读取会间歇性报 [Errno 38]。pickle.dump 大对象较慢但顺序写更稳。 读取会间歇性报 [Errno 38]。pickle.dump 大对象较慢但顺序写更稳。
""" """
import pickle import pickle
tmp = str(cache) + ".tmp"
try: try:
with open(tmp, "wb") as f: with open(cache, "wb") as f:
pickle.dump({"item_dict": item_dict, "user_seq": user_seq}, f, pickle.dump({"item_dict": item_dict, "user_seq": user_seq}, f,
protocol=pickle.HIGHEST_PROTOCOL) protocol=pickle.HIGHEST_PROTOCOL)
f.flush() f.flush()
os.fsync(f.fileno()) os.fsync(f.fileno())
os.replace(tmp, cache) print(f"[BENCH] 已缓存 -> {cache}(下次秒级读取;读不出会自动重建)")
_load_cache(cache) # 写后立即校验可读
print(f"[BENCH] 已缓存 -> {cache}")
except Exception as e: except Exception as e:
print(f"[BENCH][WARN] 缓存写入失败({e}),本次不缓存(不影响结果)") print(f"[BENCH][WARN] 缓存写入失败({e}),本次不缓存(不影响结果)")
for p in (tmp, str(cache)):
try: try:
os.remove(p) os.remove(cache)
except OSError: except OSError:
pass pass