summaryrefslogtreecommitdiff
path: root/python2
diff options
context:
space:
mode:
authorSébastien Martini <seb@dbzteam.org>2014-12-22 16:44:55 +0100
committerSébastien Martini <seb@dbzteam.org>2014-12-22 16:44:55 +0100
commitaf50b62ae18605a95cfe659b62133be411794666 (patch)
tree5a0537a2970fc17b5282f3762b998d6766a5dccd /python2
parent73a734695e9f9fcfc978ee9b72ccf29b5501c3b1 (diff)
parent6e77a4c8d001971cec6c98c6af8e553872a121d4 (diff)
downloadpyinotify-af50b62ae18605a95cfe659b62133be411794666.tar.gz
Merge pull request #85 from dano/master
Add asyncio-compatible Notifier sub-class.
Diffstat (limited to 'python2')
-rwxr-xr-xpython2/pyinotify.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/python2/pyinotify.py b/python2/pyinotify.py
index 9bc13fd..83f7766 100755
--- a/python2/pyinotify.py
+++ b/python2/pyinotify.py
@@ -1604,6 +1604,39 @@ 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):
+ """
+
+ See examples/asyncio_notifier.py for an example usage.
+
+ @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.