From c297e50a2ae0c1cdd2380a395a3ed37199580506 Mon Sep 17 00:00:00 2001 From: dano Date: Thu, 16 Oct 2014 19:43:52 -0400 Subject: Add asyncio example --- python3/examples/asyncio_notifier.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 python3/examples/asyncio_notifier.py 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() -- cgit v1.2.1