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

Luke Paireepinart rabidpoobear at gmail.com
Tue Oct 14 16:11:13 CEST 2008


Oops, replied off-list accidentally.


---------- Forwarded message ----------
From: Luke Paireepinart <rabidpoobear at gmail.com>
Date: Tue, Oct 14, 2008 at 9:10 AM
Subject: Re: [Tutor] Technical aspect of os.path.isfile()
To: W W <srilyk at gmail.com>


File renames are much faster than file copies.  So just copy the files
with an extra extension, and then when they're done copying, rename
them.  I believe that this prevents a race condition because the file
is not being exclusively accessed by the rename function.
As far as dealing with it, if you really think it's an issue, you can
always do interprocess communciation to allow them to keep up with the
current state of the other.  If that's not viable there are probably
alternatives.

On Tue, Oct 14, 2008 at 8:13 AM, W W <srilyk at gmail.com> wrote:
> 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?
>
> Thanks,
> Wayne
>
> --
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


More information about the Tutor mailing list