import pyinotify class EventHandler(pyinotify.ProcessEvent): def __init__(self, path): self.path = path def process_IN_MODIFY(self, event): print("File modified:", event.pathname) wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm) paths = ['/opt/tomcat/logs', '/home/temp'] for path in paths: wm.add_watch(path, pyinotify.IN_MODIFY, rec=True, auto_add=True, event_class=EventHandler(path)) notifier.loop(event_loop=pyinotify.EventLoop(event_class=EventHandler(path))) 报错:wm.add_watch(path, pyinotify.IN_MODIFY, rec=True, auto_add=True, event_class=EventHandler(path)) TypeError: add_watch() got an unexpected keyword argument 'event_class'
时间: 2024-01-21 15:02:07 浏览: 164
pyinotify-0.8.9.tar.gz
根据Pyinotify文档,`add_watch()`方法没有`event_class`参数。您可以尝试修改如下代码:
```
class EventHandler(pyinotify.ProcessEvent):
def __init__(self, path):
self.path = path
def process_IN_MODIFY(self, event):
print("File modified:", event.pathname)
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, EventHandler())
paths = ['/opt/tomcat/logs', '/home/temp']
for path in paths:
wm.add_watch(path, pyinotify.IN_MODIFY, rec=True, auto_add=True)
notifier.loop()
```
在这个示例中,我们将`EventHandler`作为参数传递给`Notifier`的构造函数,而不是在`add_watch()`中使用`event_class`参数。
阅读全文