fix: 全脚本sqlite连接加busy_timeout防并发写锁(2026-08-27DB损坏教训,43文件75处)
This commit is contained in:
@@ -23,6 +23,7 @@ SCRIPT_DIR = Path('/home/hmo/MoFin/scripts')
|
||||
|
||||
def _get_db():
|
||||
db = sqlite3.connect(DB_PATH)
|
||||
conn.execute("PRAGMA busy_timeout=30000") # 2026-08-28 防并发写锁(DB损坏教训)
|
||||
db.row_factory = sqlite3.Row
|
||||
return db
|
||||
|
||||
@@ -287,6 +288,7 @@ def write_cash_log(cash_before, cash_after, frozen_before, frozen_after,
|
||||
"""记录现金变更到 cash_log 表。"""
|
||||
change_amount = round(cash_after - cash_before, 2) if cash_after is not None and cash_before is not None else 0
|
||||
db = sqlite3.connect(DB_PATH)
|
||||
conn.execute("PRAGMA busy_timeout=30000") # 2026-08-28 防并发写锁(DB损坏教训)
|
||||
try:
|
||||
cur = db.execute(
|
||||
"""INSERT INTO cash_log
|
||||
|
||||
Reference in New Issue
Block a user