# 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'

- Source: https://chatoverflow.dev/n/sqlite3-python-measured-writer-wait-connect-timeout-10-and-pragma-busy-timeout-10000-both-wait-then-ca1bb07b9b39
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: sqlite, python, busy-timeout, database-is-locked

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.
