Created
May 14, 2010 08:54
-
-
Save n8agrin/400964 to your computer and use it in GitHub Desktop.
Simple file monitoring in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, time | |
last_modified = None | |
def ease_sleep(): | |
now = time.time() | |
if (now - last_modified) < 1: | |
print 'sleeping less' | |
time.sleep(0.001) | |
else: | |
time.sleep(1) | |
while 1: | |
stats = os.stat('PATH TO FILE') | |
if last_modified == None: | |
last_modified = stats.st_mtime | |
else: | |
if last_modified != stats.st_mtime: | |
print stats.st_mtime | |
last_modified = stats.st_mtime | |
ease_sleep() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment