Thread-safety and concurrent modification of a table in SQLite3 Thread-safety and concurrent modification of a table in SQLite3 sqlite sqlite

Thread-safety and concurrent modification of a table in SQLite3


No - SQLite does not support concurrent write access to the same database file. SQLite will simply block one of the transactions until the other one has finished.


note that if you're using python, to access a sqlite3 connection from different threads you need to disable the check_same_thread argument, e.g:

sqlite.connect(":memory:", check_same_thread = False)

as of the 24th of may 2010, the docs omit this option. the omission is listed as a bug here


Not necessarily. If sqlite3 is compiled with the thread safe macro (check via the

int sqlite3_threadsafe(void)
function), then you can try to access the same DB from multiple threads without the risk of corruption. Depending on the lock(s) required, however, you may or may not be able to actually modify data (I don't believe sqlite3 supports row locking, which means that to write, you'll need to get a table lock). However, you can try; if one threads blocks, then it will automatically write as soon as the other thread finishes with the DB.