wait until change

Bryan belred1 at yahoo.com
Sat Oct 18 01:23:56 EDT 2003


Aahz wrote:
> 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.

i'm currently running a python script that automatically runs when the system gets rebooted on windows.  i use the 
"scheduled tasks" control panel applet.  you can have your program scheduled to run weekly, monthly, daily, once, at 
system startup, at logon, or when idle.  you can specify start/end times, durations,  how to repeat the task, plus a 
bunch more options.

bryan





More information about the Python-list mailing list