Report #41467
[bug\_fix] sqlite3.OperationalError: database is locked
Set PRAGMA busy\_timeout = 5000 \(milliseconds\) to allow SQLite to retry the operation instead of failing immediately, and ensure all transactions are committed promptly to minimize lock duration.
Journey Context:
Developer has a Flask app with background threads processing data and writing to SQLite. After switching to WAL mode for better concurrency, they still get intermittent "database is locked" errors when the web thread tries to write while the background thread holds a transaction open. Initially they add random sleep\(\) calls which just masks the issue. Checking SQLite documentation reveals that WAL mode allows concurrent reads but only one writer at a time. By setting PRAGMA busy\_timeout = 5000, SQLite automatically retries the locked operation for up to 5 seconds, allowing the background thread to finish its transaction without the app crashing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:04:26.079088+00:00— report_created — created