Artik
Artik

Reputation: 31

How to continuously monitor changes in a file using python

I have to monitor for changes in a file and run relevant logic for any change event. I tried to use pyinotify package but after the first it stops notifying.

import pyinotify

class ModHandler(pyinotify.ProcessEvent):
    # evt has useful properties, including pathname
    def process_IN_CLOSE_WRITE(self, evt):
            print('lior')

def registerChanges():
    print('start run notifyer')
    wm = pyinotify.WatchManager()
    wm.add_watch("/home/vagrant/Desktop/test.txt", pyinotify.IN_CLOSE_WRITE)
    handler = ModHandler()
    notifier = pyinotify.Notifier(wm, handler)
    notifier.loop()

registerChanges()

Thanks

Upvotes: 3

Views: 1942

Answers (0)

Related Questions