Tags: approach, avoiding, bates, conditions, copyfile, eliminate, file, guess, larry, overwrites, programming, python, race, racegt, text, wrotegt

copyfile avoiding overwrites and race conditions

On Programmer » Python

878 words with 0 Comments; publish: Wed, 07 May 2008 18:32:00 GMT; (20048.83, « »)

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

Manuel

All Comments

Leave a comment...

  • 0 Comments