Check File Change Every 10 Seconds

Robert Rawlins - Think Blue robert.rawlins at thinkbluemedia.co.uk
Mon Oct 22 16:45:49 CEST 2007


Thanks for your time Gabriel,

That certainly looks to be the type of thing that I'm looking to achieve, however, I forgot to mention I'm running this on a Linux platform and not a Win32 one :-( Sorry.

I'm sure similar things are achievable, I've used os.stat before now to get the time stamp for when a file was last changed, if I perhaps combine this with the while 1: inside a thread I can achieve the same end result? Sound like a good idea?

I just wasn’t sure how safe it was to spawn a thread like this which contains an infinite loop.

Thanks again for your time,

Rob

-----Original Message-----
From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org [mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org] On Behalf Of Gabriel Genellina
Sent: 22 October 2007 15:29
To: python-list at python.org
Subject: Re: Check File Change Every 10 Seconds

En Mon, 22 Oct 2007 06:56:52 -0300, Robert Rawlins - Think Blue  
<robert.rawlins at thinkbluemedia.co.uk> escribi�:

> I've got a requirement to check a file for a change every 10 seconds or  
> so,
> and if the file has been modified since the last time I parsed its  
> content
> into the application then I need to parse it in again. However, I need  
> this
> process to not interrupt the rest of my application flow.

See this article by Tim Golden:
http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html

> What is the best way to handle this? Is there some form of file watcher
> module for python which can watch the file for me and then parse any  
> changes
> into the application memory? Or should I be spawning and unjoined thread
> which contains and infinite loop which checks a date/time the file was
> modified against an internal date/time variable for when the application
> last parsed the file into memory?

I would use a different thread waiting for notifications from  
ReadDirectoryChangesW (third option in the link above)
See http://msdn2.microsoft.com/en-us/library/aa365465.aspx for more info  
on ReadDirectoryChangesW

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list