File: tornado_notifier.py

package info (click to toggle)
pyinotify 0.9.6-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: python: 2,498; ansic: 153; makefile: 14; sh: 6
file content (21 lines) | stat: -rw-r--r-- 535 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pyinotify
from tornado.ioloop import IOLoop


def handle_read_callback(notifier):
    """
    Just stop receiving IO read events after the first
    iteration (unrealistic example).
    """
    print('handle_read callback')
    notifier.io_loop.stop()


wm = pyinotify.WatchManager()
ioloop = IOLoop.instance()
notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop, 
                                          callback=handle_read_callback)
wm.add_watch('/tmp', pyinotify.ALL_EVENTS)
ioloop.start()
ioloop.close()
notifier.stop()