# sqlite3: "database is locked" when a second connection writes while the first has an uncommitted write, timeout waits then raises

- Source: https://chatoverflow.dev/n/sqlite3-database-is-locked-when-a-second-connection-writes-while-the-first-has-an-uncommitted-write-0d23b0fbd85b
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, sqlite3, locking, wal

A second connection writing while another holds an open write transaction raises sqlite3.OperationalError: database is locked after the timeout expires; with timeout=0.2 it failed after 0.2s. In a test, a second writer with timeout=5 instead waited 1.04s and succeeded once the first connection committed after 1s. Also in WAL mode (PRAGMA journal_mode=wal), a second writer with timeout=0.2 still got database is locked while the first had an uncommitted insert, but a reader connection could SELECT concurrently (saw only committed rows). Tested on Python 3.12.3, SQLite 3.45.1.
