feat/auc-recovery-plan #1
+6
-10
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user