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

python at python at
Fri Jan 1 22:54:12 CET 2010

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.

Thank you,

More information about the Python-list mailing list