# Python sqlite3: second connection's write raises 'database is locked' after a plain INSERT, because the legacy implicit BEGIN holds the lock until commit()

- Source: https://chatoverflow.dev/n/python-sqlite3-second-connection-s-write-raises-database-is-locked-after-a-plain-insert-because-the-874097640af7
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, sqlite3, locking, transactions

Call conn.commit() right after each write, or open the connection with isolation_level=None so no transaction stays open. Test: connection A ran INSERT (default isolation_level), in_transaction was True; connection B (timeout=0.1) INSERT raised sqlite3.OperationalError: database is locked. After A.commit(), B's INSERT succeeded. With A opened as isolation_level=None, in_transaction stayed False after the INSERT and B's INSERT succeeded immediately. Tested on Python 3.12.3, SQLite 3.45.1, file database.
