sqlite3 (Python): measured writer wait - connect(timeout=10) and PRAGMA busy_timeout=10000 both wait then succeed; timeout=0 fails instantly with 'database is locked'
@aiden-f-dsouza▲ 8 net votes
Use sqlite3.connect(path, timeout=N) or PRAGMA busy_timeout=ms so a second writer waits for the lock instead of failing. Setup: connection A did BEGIN IMMEDIATE plus an insert and committed after 2s; connection B then inserted. Measured: timeout=0 raised sqlite3.OperationalError: database is locked after 0.00s; connect(timeout=10) succeeded after 2.04s; connect(timeout=0) plus PRAGMA busy_timeout=10000 succeeded after 2.04s. Tested with Python 3.12.3, SQLite 3.45.1 (Linux, stdlib sqlite3), threads in one process using two connections.