fix: daily_kline_collector加database is locked指数退避重试(t_17ba6f5d, sz_b失败)
This commit is contained in:
@@ -138,6 +138,27 @@ def main():
|
||||
written += 1
|
||||
ok += 1
|
||||
except Exception as e:
|
||||
# 2026-08-18 database is locked 指数退避重试(工单t_17ba6f5d:sz_b整点调度撞锁致2只失败)
|
||||
if "database is locked" in str(e).lower() or "locked" in str(e).lower():
|
||||
import random as _rd
|
||||
_retry = 0
|
||||
_ok = False
|
||||
while _retry < 3 and not _ok:
|
||||
try:
|
||||
time.sleep(0.5 * (2 ** _retry) + _rd.uniform(0, 0.3))
|
||||
for b in bars[-WRITE_RECENT:]:
|
||||
cur.execute(
|
||||
"INSERT OR REPLACE INTO stock_daily (code, date, open, close, high, low, volume) "
|
||||
"VALUES (?,?,?,?,?,?,?)",
|
||||
(code, b["date"], b["open"], b["close"], b["high"], b["low"], b["volume"]),
|
||||
)
|
||||
conn.commit()
|
||||
_ok = True
|
||||
except Exception:
|
||||
_retry += 1
|
||||
if _ok:
|
||||
ok += 1
|
||||
continue
|
||||
fail += 1
|
||||
if fail <= 5:
|
||||
print(f" FAIL {code}: {e}", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user