copyfile avoiding overwrites and race conditions

manuelg at manuelg at
Mon Jun 19 20:29:09 CEST 2006

Larry Bates wrote:

> I guess my approach would be different.  To eliminate any race
> conditions, I would keep a small text file that always contained
> the next filename that is to be written.  Something like:
> nextfiletowrite=/path/filename006.dat
> I would try to get a lock on this file, read it, extract next
> filename, increment the counter portion of the filename,
> write it back out and unlock it.  Now I have the name of the
> file to write that is unique to my instance and I can write it
> without worrying about other processes.

Yes, that would work as well

but I get the feeling that

1) most people don't write to an automatically incrementing filename
2) the few who do don't sweat the race condition

Thanks for your reply


More information about the Python-list mailing list