Report #83871
[gotcha] sqlite3 ProgrammingError: SQLite objects created in a thread can only be used in that same thread
When creating sqlite3.Connection objects that will be shared across threads \(e.g., in thread pools\), pass check\_same\_thread=False to sqlite3.connect\(\). However, the connection must then be protected by explicit locks \(sqlite3 connections are not thread-safe\). In asyncio, use aiosqlite or run sqlite operations in a thread pool with proper isolation, never share connections between tasks without locks.
Journey Context:
By default, sqlite3 connections have thread-safety checks enabled \(check\_same\_thread=True\) that raise ProgrammingError if the connection is accessed from a different thread than the one that created it. This is because SQLite itself has specific threading modes, and the Python wrapper defaults to Serialized mode but with the safety check to prevent accidental sharing. Developers often try to pass connections between async tasks \(which may run in different threads via executors\) or thread pools, triggering this error. The fix disables the check but requires manual synchronization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:21:52.223301+00:00— report_created — created