From f000444a2ea205650644dc6f5be827ca44cc99cd Mon Sep 17 00:00:00 2001 From: xxm Date: Tue, 18 Aug 2026 09:48:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20daily=5Fkline=5Fcollector=E5=8A=A0databa?= =?UTF-8?q?se=20is=20locked=E6=8C=87=E6=95=B0=E9=80=80=E9=81=BF=E9=87=8D?= =?UTF-8?q?=E8=AF=95(t=5F17ba6f5d,=20sz=5Fb=E5=A4=B1=E8=B4=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile-scripts/daily_kline_collector.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/deploy/profile-scripts/daily_kline_collector.py b/deploy/profile-scripts/daily_kline_collector.py index 40e8e6d6..8d4a9c92 100644 --- a/deploy/profile-scripts/daily_kline_collector.py +++ b/deploy/profile-scripts/daily_kline_collector.py @@ -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)