summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python3/examples/asyncio_notifier.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/python3/examples/asyncio_notifier.py b/python3/examples/asyncio_notifier.py
new file mode 100644
index 0000000..16be533
--- /dev/null
+++ b/python3/examples/asyncio_notifier.py
@@ -0,0 +1,20 @@
+import pyinotify
+import asyncio
+
+
+def handle_read_callback(notifier):
+ """
+ Just stop receiving IO read events after the first
+ iteration (unrealistic example).
+ """
+ print('handle_read callback')
+ notifier.loop.stop()
+
+
+wm = pyinotify.WatchManager()
+loop = asyncio.get_event_loop()
+notifier = pyinotify.AsyncioNotifier(wm, loop,
+ callback=handle_read_callback)
+wm.add_watch('/tmp', pyinotify.ALL_EVENTS)
+loop.run_forever()
+notifier.stop()