def watch(path, handler):
<EOL>@functools.wraps(handler)<EOL>def wrapper(self, event):<EOL><INDENT>if not event.is_directory:<EOL><INDENT>return handler(event.event_type, event.src_path)<EOL><DEDENT><DEDENT>attrs = {'<STR_LIT>': wrapper}<EOL>EventHandler = type("<STR_LIT>", (FileSystemEventHandler,), attrs)<EOL>observer = Observer()<EOL>observer.schedule(EventHandler(), path=path, recursive=True)<EOL>observer.start()<EOL>try:<EOL><INDENT>while True:<EOL><INDENT>time.sleep(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>observer.stop()<EOL><DEDENT>observer.join()<EOL>
Watch a directory for events.
    -   path should be the directory to watch
    -   handler should a function which takes an event_type and src_path
        and does something interesting. event_type will be one of 'created',
        'deleted', 'modified', or 'moved'. src_path will be the absolute
        path to the file that triggered the event.