Concurrent writes to the same file
Nobody
nobody at nowhere.com
Thu Jul 11 04:30:35 EDT 2013
On Wed, 10 Jul 2013 22:57:09 -0600, Jason Friedman wrote:
> Other than using a database, what are my options for allowing two processes
> to edit the same file at the same time? When I say same time, I can accept
> delays.
What do you mean by "edit"? Overwriting bytes and appending bytes are
simple enough, but inserting or deleting bytes such that subsequent bytes
change their offsets is harder.
> I considered lock files,
Well, you shouldn't have, unless you're targeting a platform which doesn't
support file locks (are there any left?).
> but I cannot conceive of how I avoid race conditions.
By using locks. E.g. fcntl.lockf() or msvcrt.locking().
More information about the Python-list
mailing list