How to determine if a file is busy?

Alex Martelli aleaxit at yahoo.com
Fri Oct 8 11:22:49 EDT 2004


Martin Michel <busyman at t-online.de> wrote:
   ...
> I am now trying to implement something like a temp file, which I will
> finally (after writing all the informations into it) copy into an export
> location, where the Python script can fetch it any time. My only concern is,
> if copying is also a problem (Python script reads the text file, while the
> copy process is not yet finalized...)....

Renaming, as suggested on the other subthread, sounds preferable to
copying, more likely to be an atomic operation on any kind of shared
filesystem.  Your applescript should write 'foobar.new' (either directly
in the export location, or copying it there each time it's ready) then
rename it to something like 'foobar.ready_20041008_171921' or other
unique name that's easily identifiable (this example uses a timestamp in
an order Y-M-D-h-m-s that will automatically "sort right").

Python can periodically look for 'foobar.ready_*' files in the export
location, and consume and delete them -- if it finds more than one it's
up to you whether it should consume all or just the newest one, but all
should be deleted anyway, whether they're consumed or otherwise ignored.

This protocol appears to me to be quite safe, with minimal demands on
the filesystem you're sharing.


Alex



More information about the Python-list mailing list