diff options
Diffstat (limited to 'python2/examples')
-rw-r--r-- | python2/examples/tornado_notifier.py | 21 | ||||
-rw-r--r-- | python2/examples/transient_file_tornado.py | 20 |
2 files changed, 21 insertions, 20 deletions
diff --git a/python2/examples/tornado_notifier.py b/python2/examples/tornado_notifier.py new file mode 100644 index 0000000..9390adc --- /dev/null +++ b/python2/examples/tornado_notifier.py @@ -0,0 +1,21 @@ +import pyinotify +from tornado.ioloop import IOLoop + + +def handle_read_callback(notifier): + """ + Just stop receiving IO read events after the first + iteration (unrealistic example). + """ + print('handle_read callback') + notifier.io_loop.stop() + + +wm = pyinotify.WatchManager() +ioloop = IOLoop.instance() +notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop, + callback=handle_read_callback) +wm.add_watch('/tmp', pyinotify.ALL_EVENTS) +ioloop.start() +ioloop.close() +notifier.stop() diff --git a/python2/examples/transient_file_tornado.py b/python2/examples/transient_file_tornado.py deleted file mode 100644 index a3347d3..0000000 --- a/python2/examples/transient_file_tornado.py +++ /dev/null @@ -1,20 +0,0 @@ -import pyinotify -from tornado.ioloop import IOLoop - -wm = pyinotify.WatchManager() # Watch Manager -mask = pyinotify.IN_MODIFY - -class EventHandler(pyinotify.ProcessEvent): - def process_IN_MODIFY(self, event): - # We have explicitely registered for this kind of event. - print '\t', event.pathname, ' -> written' - def process_default(self, event): - print event - -ioloop = IOLoop.instance() -notifier = pyinotify.TornadoAsyncNotifier(wm, ioloop) -#daemon.pids['nginx'] -wdd = wm.watch_transient_file('/tmp/test_file', pyinotify.IN_MODIFY, - EventHandler) - -ioloop.start() |