修复持仓轮询时 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
+8
View File
@@ -76,7 +76,13 @@ def trading_day_reset_hour() -> int:
return 8
_SCHEMA_READY = False
def ensure_account_risk_schema(conn) -> None:
global _SCHEMA_READY
if _SCHEMA_READY:
return
conn.execute(
"""CREATE TABLE IF NOT EXISTS account_risk_state (
id INTEGER PRIMARY KEY CHECK (id = 1),
@@ -93,6 +99,8 @@ def ensure_account_risk_schema(conn) -> None:
conn.execute(
"INSERT INTO account_risk_state (id, trading_day, manual_close_count, daily_frozen) VALUES (1, '', 0, 0)"
)
conn.commit()
_SCHEMA_READY = True
def _row_get(row, key, default=None):