Need to monitor a file change/deletion

Aaron Mahler amahler at sbc.edu
Mon Oct 25 01:40:32 EDT 1999


 Hello!

  I was wondering if I might elicit some recommendations on how to
achieve what seems like a simple task, but has so far stumped me...

  I need to find a decent, low-impact way to monitor a file and see if
it has changed. Basically, I need a blocking routine (no timeouts needed
at this stage) that will keep an eye on a specific regular file and
unblock when the file has been replaced. In this case, the file is
arriving via FTP, I'm reading it in, closing it, and then waiting for it
to be replaced with a newly FTP'd file by the same name (replacing it,
in other words). 

  In a nutshell, this script is monitoring JPEGS coming in via FTP on a
varying schedule and pushing them out via CGI/nph to a varying number of
attached clients... I want the newly arrived image to go out ASAP, but
want to also avoid sending the same image out over and over (a set
timeframe) if it's taking extra-long for the new image to arrive. Since
the image feed is FTP from a remote host, I've not figured a way to use
some select()-capable sort of locks and sockets mechanism like I would
if the entire process were local.

  I don't want to go into any kind of CPU-intensive loop checking the
timestamp, etc. I could just choose a short timeframe (seconds) for
rechecking to keep from creating a tight loop, but I'd much rather have
the process sleep and be reawakened by some sort of signal. 

  select() looks nice and basically fits the bill in terms of
functionality - but apparently doesn't work with regular files if I'm
not mistaken...

  Any recommendations would be greatly appreciated! :)

Thanks!
 - Aaron Mahler


-- 
PGP Public Key - http://sparhawk.sbc.edu/amahler.pgp
VAPS Entry - http://www.vaps.org/members/va/amahler@sbc.edu.html
--




More information about the Python-list mailing list