summaryrefslogtreecommitdiff
path: root/python2/examples/tornado_notifier.py
diff options
context:
space:
mode:
Diffstat (limited to 'python2/examples/tornado_notifier.py')
-rw-r--r--python2/examples/tornado_notifier.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/python2/examples/tornado_notifier.py b/python2/examples/tornado_notifier.py
new file mode 100644
index 0000000..9390adc
--- /dev/null
+++ b/python2/examples/tornado_notifier.py
@@ -0,0 +1,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()