write to the same file from multiple processes at the same time?
Peter Hansen
peter at engcorp.com
Fri May 27 18:06:41 EDT 2005
Paul Rubin wrote:
> http://www.sqlite.org/faq.html#q7
[snip]
> Multiple processes can have the same database open at the same
> time. Multiple processes can be doing a SELECT at the same
> time. But only one process can be making changes to the database
> at once.
>
> But multiple processes changing the database simultaneously is
> precisely what the OP wants to do.
What isn't described in the above quote from the FAQ is how SQLite
*protects* your data from corruption in this case, unlike the "raw"
approach where you just use file handles.
And PySQLite conveniently wraps the relevant calls with retries when the
database is "locked" by the writing process, making it roughly a
no-brainer to use SQLite databases as nice simple log files where you're
trying to write from multiple CGI processes like the OP wanted.
Disclaimer: I haven't actually done that myself, and have only started
playing with pysqlite2 a day ago, but I have spent a fair bit of time
experimenting and reading the relevant docs and I believe I've got this
all correct.
-Peter
More information about the Python-list
mailing list