diff options
author | Sebastien Martini <seb@dbzteam.org> | 2012-10-04 00:45:11 +0200 |
---|---|---|
committer | Sebastien Martini <seb@dbzteam.org> | 2012-10-04 00:45:11 +0200 |
commit | 75f63f3f63ed1105b5cad98e1121dc55e5043cba (patch) | |
tree | 10369427d4bd97720144d843839f5d5d71f12daf | |
parent | 8599f88bf9c4217861ebac681362b96d98c2c000 (diff) | |
download | pyinotify-75f63f3f63ed1105b5cad98e1121dc55e5043cba.tar.gz |
Ported TornadoAsyncNotifier to Python3.
Assuming Tornado works the same way under Python3... I must say
I don't use Tornado myself I didn't test it.
-rw-r--r-- | python2/examples/transient_file_tornado.py | 5 | ||||
-rwxr-xr-x | python2/pyinotify.py | 20 | ||||
-rwxr-xr-x | python3/pyinotify.py | 27 |
3 files changed, 43 insertions, 9 deletions
diff --git a/python2/examples/transient_file_tornado.py b/python2/examples/transient_file_tornado.py index 554f3cd..a3347d3 100644 --- a/python2/examples/transient_file_tornado.py +++ b/python2/examples/transient_file_tornado.py @@ -14,6 +14,7 @@ class EventHandler(pyinotify.ProcessEvent): ioloop = IOLoop.instance() notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop) #daemon.pids['nginx'] -wdd = wm.watch_transient_file('/tmp/test_file', pyinotify.IN_MODIFY, EventHandler) +wdd = wm.watch_transient_file('/tmp/test_file', pyinotify.IN_MODIFY, + EventHandler) -ioloop.start()
\ No newline at end of file +ioloop.start() diff --git a/python2/pyinotify.py b/python2/pyinotify.py index 6ca990d..82592a8 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -1539,20 +1539,26 @@ class AsyncNotifier(asyncore.file_dispatcher, Notifier): self.read_events() self.process_events() + class TornadoAsyncNotifier(Notifier): """ - Tornado ioloop adapter + Tornado ioloop adapter. """ - def __init__(self, watch_manager, ioloop, default_proc_fun=None, read_freq=0, - threshold=0, timeout=None, channel_map=None): + def __init__(self, watch_manager, ioloop, default_proc_fun=None, + read_freq=0, threshold=0, timeout=None, channel_map=None): + """ + See example transient_file_tornado.py + + @param ioloop: Tornado's IO loop. + @type ioloop: tornado.ioloop.IOLoop instance. + """ Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout) ioloop.add_handler(os.dup(self._fd), self.handle_read, ioloop.READ) - def handle_read(self,*args,**kwargs): + + def handle_read(self, *args, **kwargs): """ - When asyncore tells us we can read from the fd, we proceed processing - events. This method can be overridden for handling a notification - differently. + See comment in AsyncNotifier. """ self.read_events() diff --git a/python3/pyinotify.py b/python3/pyinotify.py index a826efb..6c52708 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1535,6 +1535,33 @@ class AsyncNotifier(asyncore.file_dispatcher, Notifier): self.process_events() +class TornadoAsyncNotifier(Notifier): + """ + Tornado ioloop adapter. + + """ + def __init__(self, watch_manager, ioloop, default_proc_fun=None, + read_freq=0, threshold=0, timeout=None, channel_map=None): + """ + See example transient_file_tornado.py + + @param ioloop: Tornado's IO loop. + @type ioloop: tornado.ioloop.IOLoop instance. + + """ + Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, + threshold, timeout) + ioloop.add_handler(os.dup(self._fd), self.handle_read, ioloop.READ) + + def handle_read(self, *args, **kwargs): + """ + See comment in AsyncNotifier. + + """ + self.read_events() + self.process_events() + + class Watch: """ Represent a watch, i.e. a file or directory being watched. |