修复持仓轮询时 SQLite database is locked 错误。

单连接复用并提交风控写入,启用 WAL 与 busy_timeout,缓存风控表 schema 初始化。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-24 10:27:04 +08:00
parent 87aef80594
commit 1688452f3f
3 changed files with 52 additions and 31 deletions
+6 -1
View File
@@ -158,8 +158,13 @@ def expire_old_plans():
# —————————————— 设置读写 ——————————————
def get_db():
conn = sqlite3.connect(DB_PATH)
conn = sqlite3.connect(DB_PATH, timeout=30)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA busy_timeout=30000")
try:
conn.execute("PRAGMA journal_mode=WAL")
except sqlite3.OperationalError:
pass
return conn