Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python连续监视文件中的更改_Python_Linux_Pyinotify - Fatal编程技术网

如何使用python连续监视文件中的更改

如何使用python连续监视文件中的更改,python,linux,pyinotify,Python,Linux,Pyinotify,我必须监视文件中的更改,并为任何更改事件运行相关逻辑。 我尝试使用pyinotify包,但在第一次使用后,它停止通知 import pyinotify class ModHandler(pyinotify.ProcessEvent): # evt has useful properties, including pathname def process_IN_CLOSE_WRITE(self, evt): print('lior') def regis

我必须监视文件中的更改,并为任何更改事件运行相关逻辑。 我尝试使用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()

谢谢

检查您正在运行的python版本。可能与