Wait for events and print them to stdout.

def watch_for_events():
    """Wait for events and print them to stdout."""
    fd = inotify.init()
    try:
        wd = inotify.add_watch(fd, '/tmp', inotify.IN_CLOSE_WRITE)
        while True:
            for event in inotify.get_events(fd):
                print("event:", event.name, event.get_mask_description())
    finally:
        os.close(fd)