How do I watch a file for changes using Python?
Posted
by Jon Cage
on Stack Overflow
See other posts from Stack Overflow
or by Jon Cage
Published on 2008-10-08T11:12:55Z
Indexed on
2010/06/13
5:22 UTC
Read the original article
Hit count: 295
I have a log file being written by another process which I want to watch for changes. Each time a change occurrs I'd like to read the new data in to do some processing on it.
What's the best way to do this? I was hoping there'd be some sort of hook from the PyWin32 library. I've found the win32file.FindNextChangeNotification function but have no idea how to ask it to watch a specific file.
If anyone's done anything like this I'd be really grateful to hear how...
[Edit] I should have mentioned that I was after a solution that doesn't require polling.
[Edit] Curses! It seems this doesn't work over a mapped network drive. I'm guessing windows doesn't 'hear' any updates to the file the way it does on a local disk.
© Stack Overflow or respective owner