Safe file I/O to shared file (or SQLite) from multi-threaded web server

John Nagle nagle at
Sun Jan 3 07:40:31 CET 2010

python at wrote:
> I'm looking for the best practice way for a multi-threaded python web
> server application to read/write to a shared file or a SQLite database.
> What do I need to do (if anything) to make sure my writes to a regular
> file on disk or to a SQLite database are atomic in nature when multiple
> clients post data to my application simultaneously?

    SQLite can do that correctly, but SQLite isn't intended for use
as a database engine for a busy database being used by many
concurrent operations.  Especially if those operations involve
updates.  Any update in SQLite locks all tables involved for the duration
of the operation.  When SQLite hits a lock, it returns an error code, and
the caller should retry after a delay.  If this occurs frequently in
your application, you've hit the limits of SQLite.  Then it's
time to move up to MySQL.

   If you have enough traffic that you need a multi-threaded web server,
it's probably time to move up.

				John Nagle

More information about the Python-list mailing list