简体   繁体   中英

Python watchdog script doesn't function properly

I am trying to use Python Watchdog to monitor a directory for changes. However, when I try to run the Quickstart example:

import time
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler

if __name__ == "__main__":
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path='.', recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

by putting in it the file test.py , nothing displays in the Terminal window where I ran it. What is causing this to happen, and how can I fix it?

Try the example on github: https://github.com/gorakhargosh/watchdog

This example seems to work as opposed to the one on the docs site that does not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM