The flag you'll bump into immediately
By default, a Python sqlite3.Connection can only be used from the thread that created it. Use it from a different thread and you get ProgrammingError: SQLite objects created in a thread can only be used in that same thread.
Three ways to handle multi-threaded apps:
- One connection per thread — typically via
threading.local(). Simple and safe. - Connection pool — if your app has many short-lived threads. Tools like SQLAlchemy do this for you.
- check_same_thread=False + your own lock — disable the safety check and serialize access yourself. Easy to mess up; only do this if you know exactly what you're doing.
Self-reference: Pippa's backend uses
aiosqlite (covered in track 7) instead of threads, which sidesteps this entirely — async tasks run on one thread by definition. For sync threaded code, the per-thread connection pattern is the boring, correct default.