How to determine if a file is busy?

Martin Michel busyman at t-online.de
Fri Oct 8 10:34:14 EDT 2004


"Alex Martelli" <aleaxit at yahoo.com> schrieb im Newsbeitrag
news:1glcbu7.po1w0e8mxyl6N%aleaxit at yahoo.com...
> 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.
>
>
> Alex

First of all: Thanks so much for your help! I am really astonished about
everybody doing his best to find a solution for my problem.

It might sound funny, but it is not important, that a specific data file has
already been consumed. For me, it is only important, that my Python script
does not open & read a file, which is currently in use by my AppleScript.
It's more like a webcam thing: If a picture taken by the cam, is not put
into the album/webserver, that is no problem, because there will be other
pictures taken by the cam in the future.

The platform independence of Python is great for me as I can fetch the
informations from a Windows XP PC and a Mac to feed the database running in
our electroplating company, but I am also happy to program all the rest of
the application in Python, because as much as I do like AppleScript (Studio)
for its power on the Mac, I hate writing its longish code leading to big
scripts doing little things...Python is just so snappy ;-) (for someone who
has coded a long time in AppleScript)

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...)....

Thanks so much once again, you are a great community, Python is a great
lannguage!

Martin





More information about the Python-list mailing list