我对 pyinotify 有疑问:未调用process_*()
的方法ProcessEvent
编码
import sys, time, syslog
from pyinotify import WatchManager, Notifier, ThreadedNotifier, ProcessEvent, EventsCodes
from daemon import Daemon
class PTmp(ProcessEvent):
def process_IN_CREATE(self, event):
syslog.syslog("creating: " + event.pathname)
def process_IN_DELETE(self, event):
syslog.syslog("creating: " + event.pathname)
def process_default(self, event):
syslog.syslog("default: " + event.pathname)
class MyDaemon(Daemon):
def run(self):
syslog.openlog('archmind',syslog.LOG_PID,syslog.LOG_DAEMON)
syslog.syslog('daemon started, entering loop')
wm = WatchManager()
mask = IN_DELETE | IN_CREATE
notifier = ThreadedNotifier(wm, PTmp())
notifier.start()
wdd = wm.add_watch('/tmp', mask, rec=True)
while True:
time.sleep(1)
wm.rm_watch(wdd.values())
notifier.stop()
syslog.syslog('exiting loop')
syslog.closelog()
if __name__ == "__main__":
daemon = MyDaemon('/tmp/archmind.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)
其他所有内容都已记录。inofity 工作正常,我已经用 inotifywait 对其进行了测试。我可能会错过什么?