Single Instance of app
Tim Hammerquist
tim at vegeta.ath.cx
Wed Aug 29 17:15:47 EDT 2001
Me parece que Tim Peters <tim.one at home.com> dijo:
> [Tim Peters]
> > I'm not sure exactly what's meant by "atomic lock on a file",
> > but you can study the std tempfile.py module for the excruciating dance
> > needed to create temp files safely.
>
> [Tim Hammerquist]
> > Thanks!
>
> Hey, what else are Tims good for <wink>?
<g>
> > I just meant 'atomic' as far as avoiding the race condition.
>
> Cool. You have primarily the O_EXCL flag to os.open() to thank for that.
That's exactly what I was looking for.
> > The tempfile module uses the ((fd)?open|close) functions in the os
> > module. I would assume these are closer to the system calls like
> > fopen() and fdopen() than is the built-in open()?
>
> Python C
> ----------------- -------
> __builtin__.open fopen
> __builtin__.close fclose
> os.open open
> os.close close
> os.fdopen fdopen
>
> The problem is that O_EXCL isn't available to (C) fopen, so the low-level
> open has to be used. Then the file is unlinked, both so that it will go
> away when the descriptor is closed, and so that nobody can find it *by* name
> via directory searches. Then we're left with a raw file handle, but Python
> file objects wrap streams; fdopen is used just to wrap a stream around the
> handle.
Ah. Thanks for the excellent explanation. Now I can avoid a few mistakes
that would've been very embarrassing. <wink>
(Another) Tim
--
Abel had been dead for a couple of hours now.
But he was starting to feel better.
-- Narrator, The Sandman
More information about the Python-list
mailing list