擅长:python、mysql、java
<p>特别是要用dbus循环编织notify内容,技巧是使用来自<code>pyinotify</code>的<code>ThreadedNotifier</code>。我用了这样的方法:</p>
<pre><code>watchManager = pyinotify.WatchManager()
inotifier = pyinotify.ThreadedNotifier(watchManager, FileEventHandler(mainService.eventStream))
inotifier.start()
eventsPath = Path('/Pilot/Schedules')
if not eventsPath.exists():
eventsPath.mkdir()
watchManager.add_watch(eventsPath.as_posix(), pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE, rec=True, auto_add=True)
mainloop = glib.MainLoop()
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()
inotifier.stop()
</code></pre>
<p>我的<code>FileEventHandler</code>使用了<code>process_IN_CLOSE_WRITE</code>等标准方法来提交dbus更改。你知道吗</p>