summaryrefslogtreecommitdiff
path: root/python2
diff options
context:
space:
mode:
authordano <oreilldf@gmail.com>2014-10-16 19:40:49 -0400
committerdano <oreilldf@gmail.com>2014-10-16 19:40:49 -0400
commitb1da9d65979ed50eca42d68814fd99badece1de3 (patch)
tree502dfa63290a6d5ea394cdf58c8bb5554df01842 /python2
parenta51277db95321eae90656e1fbc4ef8b11584735f (diff)
downloadpyinotify-b1da9d65979ed50eca42d68814fd99badece1de3.tar.gz
Add asyncio Notifier adapter
Diffstat (limited to 'python2')
-rwxr-xr-xpython2/pyinotify.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/python2/pyinotify.py b/python2/pyinotify.py
index 7733337..a12ce3f 100755
--- a/python2/pyinotify.py
+++ b/python2/pyinotify.py
@@ -1604,6 +1604,37 @@ class TornadoAsyncNotifier(Notifier):
self.handle_read_callback(self)
+class AsyncioNotifier(Notifier):
+ """
+
+ asyncio/trollius event loop adapter.
+
+ """
+ def __init__(self, watch_manager, loop, callback=None,
+ default_proc_fun=None, read_freq=0, threshold=0, timeout=None):
+ """
+
+ @param loop: asyncio or trollius event loop instance.
+ @type loop: asyncio.BaseEventLoop or trollius.BaseEventLoop instance.
+ @param callback: Functor called at the end of each call to handle_read.
+ Expects to receive the notifier object (self) as
+ single parameter.
+ @type callback: callable object or function
+
+ """
+ self.loop = loop
+ self.handle_read_callback = callback
+ Notifier.__init__(self, watch_manager, default_proc_fun, read_freq,
+ threshold, timeout)
+ loop.add_reader(self._fd, self.handle_read)
+
+ def handle_read(self, *args, **kwargs):
+ self.read_events()
+ self.process_events()
+ if self.handle_read_callback is not None:
+ self.handle_read_callback(self)
+
+
class Watch:
"""
Represent a watch, i.e. a file or directory being watched.