Skip to content

Instantly share code, notes, and snippets.

@n8agrin
Created May 14, 2010 08:54
Show Gist options
  • Save n8agrin/400964 to your computer and use it in GitHub Desktop.
Save n8agrin/400964 to your computer and use it in GitHub Desktop.
Simple file monitoring in python
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