我使用pyinotify.notifier来跟踪文本文件中的更改。
当我在它中得到一个特定的更改时,我想要中断通知器循环。通过使用notifier.stop()似乎不起作用。
以下是我要做的事:
class ModHandler(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, evt):
#... Do Stuff
if "Expected change":
#break notifier loop
if __name__ == "__main__":
handler = ModHandler()
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch('example.file', pyinotify.IN_MODIFY)
notifier.loop()
#when finished the loop, do more stuff如何才能中断线程循环并返回到主程序?
发布于 2017-12-11 12:25:14
发布于 2019-09-12 17:01:25
从0.9.0版本开始,您可以通过传递回调函数来停止通知器循环。当求值为True时,中断循环并停止通知程序。
https://github.com/seb-m/pyinotify/wiki/Recent-Developments#changes-introduced-with-pyinotify-090
https://stackoverflow.com/questions/47752723
复制相似问题