How to determine if a file is busy?
b.niemann at betternet.de
Fri Oct 8 16:00:32 CEST 2004
Alex Martelli wrote:
> 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...
The AppleScript could rename the .new file to .[timestamp], producing a new file
for each iteration. The Python script would consume & delete all .[timestamp]
files in lexical order, but must ignore the .new file if it happens to be there.
More information about the Python-list