pyinotify.ThreadedNotifier,process_* 未调用
我在使用 pyinotify 时遇到问题: ProcessEvent
的方法 process_*()
未调用
代码
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 对其进行了测试。我可能缺少什么?
I have a problem with pyinotify: the methods process_*()
of the ProcessEvent
are not called
The code
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)
Everything else is logged. inofity works correctly, I have tested it with inotifywait. What may I be missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于缺少 IN_* 的导入,这必须手动完成。我在调用后发现了这一点,
而不是
使脚本在前台运行。
The problem was missing the import of IN_*, which has to be done manually. I've found that out after calling
instead of
thus making the script run in foreground.
掩码在 EventCodes.ALL_FLAGS 中定义
masks are defined in EventCodes.ALL_FLAGS