wait until change

Peter Hansen peter at engcorp.com
Fri Oct 17 15:26:06 EDT 2003


Tom wrote:
> 
> Peter Hansen wrote:
> 
> >Use time.sleep().
> >
> >-Peter
> >
> If I use sleep, I have to know how long the process should sleep, but
> sometimes it should sleep for seconds and sometimes for minutes. So it
> would be good if I can put it to sleep and somehow wake it up if the
> file changed.

See Tim's excellent reply.

Also, note that there are non-cross-platform solutions that basically
notify your program "as soon as" (possibly without any latency guarantees)
a change has happened.  They are harder to use and quite likely unnecessary
in your case, and the time.sleep() approach Tim points out is simpler
and therefore the best thing to start with.

You do have to confirm of course that this other application won't 
be writing to the file so often that you might run into trouble. 

Does this other program write updates infrequently, and does your 
Python analysis script run quickly enough, that if your code wakes 
up within a few seconds of each update it will complete its work
soon enough to avoid problems?

-Peter




More information about the Python-list mailing list