SQLite3: Beware of Concurrency

SQLite3 is a very lightweight implementation of a SQL database.  I’ve been using it in conjunction with Python on a single-threaded tool.  This morning I started refactoring my tool to have multi-process support, but I was interrupted by the following error:

sqlite3.OperationalError: database is locked

After reading through the SQLite3 documentation, I found that SQLite3 does database-level locking when performing write operations.  This means that all hope of parallelizing SQLite3 write operations is lost, because SQLite rejects a concurrent write attempt to the same database.

And I thought MySQL‘s table-level locking was bad (unless you’re using InnoDB) …

Update: for the record, PostreSQL does row-level locking.