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

Diez B. Roggisch deets at
Fri Jan 1 23:20:19 CET 2010

python at schrieb:
> 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?
> Do I need to use a Queue type data structure and then run a background
> thread that monitors my Queue for data which it (and it alone) removes
> and copies to the destination file or SQLite datatbase?
> Note: In my specific case, the web server will be based on CherryPy 3.1
> but I think this type of question is relevant across other Python based
> web server frameworks as well.

AFAIK, sqlite ensures process-serialization via locking, and threads 
synchronize themselves as well.

So you shouldn't need to worry at all.


More information about the Python-list mailing list