简体   繁体   English

Python看门狗脚本无法正常运行

[英]Python watchdog script doesn't function properly

I am trying to use Python Watchdog to monitor a directory for changes. 我正在尝试使用Python Watchdog来监视目录中的更改。 However, when I try to run the Quickstart example: 但是,当我尝试运行Quickstart示例时:

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. 通过输入文件test.py ,我运行它的终端窗口中没有显示任何内容。 What is causing this to happen, and how can I fix it? 是什么导致这种情况发生,我该如何解决?

Try the example on github: https://github.com/gorakhargosh/watchdog 试试github上的例子: https//github.com/gorakhargosh/watchdog

This example seems to work as opposed to the one on the docs site that does not. 这个例子似乎与文档网站上没有的例子相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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