[Tutor] Technical aspect of os.path.isfile()

W W srilyk at gmail.com
Tue Oct 14 15:13:55 CEST 2008

I suppose this is really more of a technical aspect, dealing with the
possibility of a race condition (although in my personal case, the
probability is infinitely small).

I'm writing a program that uses the ConfigParser module to open a config
file, and if that file isn't present, I'd like to create it. I'll also be
syncing a series of files from one directory to another. I'll be creating a
list of files in each dir using os.walk, and copying the files that aren't
present in the destination dir.

 After looking online I've found various opinions on what the "best" way is
to deal with the possibility of a race condition. The way I intend to use my
program, a race condition should never occur, but if I ever release the
source, I'd like it to at least fail gracefully.

Is there a solid way to prevent a race condition, or is it just sort of a
"do your best" type situation?


To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081014/3c00aa46/attachment.htm>

More information about the Tutor mailing list