我必须监视文件中的更改并为任何更改事件运行相关逻辑。我尝试使用 pyinotify 包,但在第一次之后它停止通知。
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()
谢谢