1import pyinotify
2from tornado.ioloop import IOLoop
3
4
5def handle_read_callback(notifier):
6    """
7    Just stop receiving IO read events after the first
8    iteration (unrealistic example).
9    """
10    print('handle_read callback')
11    notifier.io_loop.stop()
12
13
14wm = pyinotify.WatchManager()
15ioloop = IOLoop.instance()
16notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop,
17                                          callback=handle_read_callback)
18wm.add_watch('/tmp', pyinotify.ALL_EVENTS)
19ioloop.start()
20ioloop.close()
21notifier.stop()
22