Handling Multiple Event Handlers

79 views
Skip to first unread message

Usman Ehtesham

unread,
Jan 25, 2016, 10:18:09 PM1/25/16
to watchdog-python
Hello,

I am a first time user of watchdog. I wanted to how can watchdog handle multiple handlers. Would it be something like this:

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler_1 = LoggingEventHandler()
    event_handler_2 = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler_1, path, recursive=True)
    observer.schedule(event_handler_2, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

Would appreciate help in this?

Jeffrey DeLeo

unread,
Feb 5, 2016, 12:47:24 PM2/5/16
to watchdog-python
Not quite sure what you are trying to achieve - you would like two event handlers to respond to events in the same directory tree?
I have multiple observers in my application, but they are running on disjoint directory trees, in separate threads.
Reply all
Reply to author
Forward
0 new messages