wait until change

Aahz aahz at pythoncraft.com
Sat Oct 18 00:48:14 EDT 2003


In article <bmp5nv$e0d$1 at news.uni-kl.de>, Tom  <llafba_NOSPAM_ at gmx.net> wrote:
>
>I have the following problem. I analyse data from a file. When I am done 
>analysing all the data that was in that file, I want to let my program 
>wait until this specific file has changed (which indicates that new data 
>has been added to the file from a third party program that I don't 
>control). If that file has changed, I want my program to continue.
>
>What would be the appropriate command to check if the file changed? And 
>how can I implement "wait until" into my program? I googled a lot to 
>find any hints, but couldn't find anything helpful. But I found 
>something about a python that was stabbed in NY in 2000. :-) Thought 
>that was funny. :-)

os.stat() is the correct answer, but I question the other responses that
suggest using time.sleep().  Unless your application stores a lot of
data in memory, you might be better off using your OS to periodically
run your application; your application stores the result of os.stat() in
a private file.  On Unix-like systems, the facility is called cron;
dunno what that would be on Windows.  This would simplify your program;
it also means your program would automatically start when the system
gets rebooted.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan




More information about the Python-list mailing list