[英]pyinotify can not watch current dir
I put a script using pyinotify under my home dir (/home/name) and run it. 我在主目录(/ home / name)下使用pyinotify放置了一个脚本并运行它。 While I can not make the script watch my home dir (/home/name) or dirs that contain my home dir, like root (/) and /home/. 虽然我无法使脚本监视我的主目录(/ home / name)或包含我的主目录的目录,例如root(/)和/ home /。 All other dirs are OK, like /var, /boot, /home/name/Documents. 其他所有目录都可以,例如/ var,/ boot,/ home / name / Documents。
Let me describe it in a clean way: 让我以一种简洁的方式来描述它:
dirs that are NOT OK:
/
/home
/home/name (script is here)
All other dirs are OK, e.g.
/bin
/var
/home/name/Documents
Script: 脚本:
import pyinotify
class MyEventHandler(pyinotify.ProcessEvent):
def process_IN_ACCESS(self, event):
print "ACCESS event:", event.pathname
def process_IN_ATTRIB(self, event):
print "ATTRIB event:", event.pathname
def process_IN_CLOSE_NOWRITE(self, event):
print "CLOSE_NOWRITE event:", event.pathname
def process_IN_CLOSE_WRITE(self, event):
print "CLOSE_WRITE event:", event.pathname
def process_IN_CREATE(self, event):
print "CREATE event:", event.pathname
def process_IN_DELETE(self, event):
print "DELETE event:", event.pathname
def process_IN_MODIFY(self, event):
print "MODIFY event:", event.pathname
def process_IN_OPEN(self, event):
print "OPEN event:", event.pathname
def main():
# watch manager
wm = pyinotify.WatchManager()
wm.add_watch('/var/log', pyinotify.ALL_EVENTS, rec=True)
# event handler
eh = MyEventHandler()
# notifier
notifier = pyinotify.Notifier(wm, eh)
notifier.loop()
if __name__ == '__main__':
main()
认为您需要为您的主目录指定手表。
wm.add_watch('/home', pyinotify.ALL_EVENTS, rec=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.