How to determine if a file is busy?

Alex Martelli aleaxit at yahoo.com
Fri Oct 8 09:31:52 EDT 2004


Andreas Kostyrka <andreas at kostyrka.org> wrote:

> On Fri, Oct 08, 2004 at 01:54:03PM +0200, Alex Martelli wrote:
> > Benjamin Niemann <b.niemann at betternet.de> wrote:
> > 
> > > How about writing the data to a file 'mydata.new' and when you are
> > > finished, delete 'mydata' and rename 'mydata.new' to 'mydata'. This
> > > way the python script will always get 'complete' files (and sometimes
> > > no file at all, when it come in between rm and mv ...)
> > 
> > I believe that 'mv' on Mac OS X, within a normal filesystem, is an
> > atomic operation anyway -- so, so need to rm first then mv.  On the
> > other hand, this would give no intrinsic guarantee that the datafile
> > previously produced HAS been consumed/recorded before it's removed.
> Then the consumer of that file should remove it afterwards.

Possibly, but that, per se, doesn't mean a file can't get deleted
without ever having been used.  If the producer must wait for the
deletion (not necessarily easy in AppleScript, I believe) then the
producer could be stalled by the implied 1-length 'queue'...

I'm not sure about the best solution because I'm unsure about the exact
abilities of AppleScript, where the Python script is running (on Windows
with a [EEK] SMB share to the Mac, or on the Mac itself), etc...


Alex



More information about the Python-list mailing list