summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordano <oreilldf@gmail.com>2014-10-16 19:43:52 -0400
committerdano <oreilldf@gmail.com>2014-10-16 19:43:52 -0400
commitc297e50a2ae0c1cdd2380a395a3ed37199580506 (patch)
tree3919ee7d56f98646eafe63484db2c57dd86c47e8
parentb1da9d65979ed50eca42d68814fd99badece1de3 (diff)
downloadpyinotify-c297e50a2ae0c1cdd2380a395a3ed37199580506.tar.gz
Add asyncio example
-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()