Concurrent writes to the same file

J

Jason Friedman

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. I considered lock files, but I cannot conceive of how I avoid race
conditions.
 
N

Nobody

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().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top