root / stats_threaded.py

Revision ca5ddc5f5eea62c76b6be75a1fbdedf663dbcfd0, 0.9 kB (checked in by Sebastien Martini <ookoi@…>, 5 months ago)

Flag example files as 'Example'.

  • Property mode set to 100644
Line 
1# Example
2#
3import time
4from pyinotify import *
5
6# Do the same thing than stats.py but with a ThreadedNotifier's
7# instance.
8# This example illustrates the use of this class but the recommanded
9# implementation is whom of stats.py
10
11
12class Identity(ProcessEvent):
13
14    def process_default(self, event):
15        # Does nothing, just to demonstrate how stuffs could be done
16        # after having processed statistics.
17        pass
18
19
20wm = WatchManager()
21s = Stats() # Stats is a subclass of ProcessEvent
22notifier = ThreadedNotifier(wm, default_proc_fun=Identity(s))
23notifier.start()
24wm.add_watch('/tmp/', ALL_EVENTS, rec=True, auto_add=True)
25
26while True:
27    try:
28        print repr(s)
29        print
30        print s
31        print
32        time.sleep(5)
33    except KeyboardInterrupt:
34        print 'stop monitoring...'
35        notifier.stop()
36        break
37    except Exception, err:
38        print err
Note: See TracBrowser for help on using the browser.