#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
from pyinotify import ThreadedNotifier, WatchManager, EventsCodes, ProcessEvent
if __name__ == '__main__':
path = '/home/blabla/tmp/file.txt'
mask = EventsCodes.ALL_EVENTS
wm = WatchManager()
notifier = ThreadedNotifier(wm, ProcessEvent())
notifier.start()
wm.add_watch(path, mask, None, True, True, True)
print 'start monitoring %s with mask 0x%08x' % (path, mask)
while True:
try:
import time
time.sleep(5)
except KeyboardInterrupt:
print 'stop monitoring...'
notifier.stop()
break
except Exception, err:
print err