Menu

1 / 2

Fixing "database is locked" and Float Drift in Concurrent Python SQLite Apps

DEV Community: python·zheomara·3 days ago
#HodoV6mc
#devtopython#devto#dev#conn#self
Long article (2222 words) — no AI summary yet.
Reading 0:00
15s threshold

Python's built-in sqlite3 module works cleanly in single-threaded scripts, right up until you combine a UI loop, background polling workers, and financial totals in the same desktop app. On Windows especially, three subtle problems surface fast:

Concurrent readers and writers collide with sqlite3.OperationalError: database is locked under default DELETE rollback journaling.

Opening and closing sqlite3.connect(path) on every helper call forces repeated PRAGMA setup and triggers SQLite WAL checkpoint/unlink cycles when the last handle closes, turning sub-millisecond writes into 200 to 440ms disk stalls.

Tracking dollar amounts as float accumulates binary rounding drift, while naive ON CONFLICT DO UPDATE queries quietly wipe existing local notes whenever a lightweight sync passes an empty string.

Enabling PRAGMA journal_mode = WAL , keeping persistent per-thread connections behind an RLock , versioning schema migrations, and storing currency strictly in integer cents ( amount_cents ) solves these issues…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.