相关疑难解决方法(0)

看门狗在Python 3中获得三次事件

我正在使用Watchdog在Python中创建一个程序,该程序监视一组文件并根据更改采取操作.我把他们网站上的确切示例放在一个文件中:

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

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 = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
Run Code Online (Sandbox Code Playgroud)

然后,我注意到一些奇怪的事情 我以相同的方式为Python 2和Python 3安装了看门狗(使用pip2 install watchdogpip3 install watchdog).然而,当我运行在Python 2和3的程序,做同样的修改一次每个,出现这种情况:

$ python2 watch_test.py
2015-09-30 11:18:32 - Modified …
Run Code Online (Sandbox Code Playgroud)

python python-2.x python-3.x python-watchdog

8
推荐指数
0
解决办法
812
查看次数

python watchdog修改并创建了重复事件

在Ubuntu上运行,每次创建文件时我都会获得修改后的事件.

这是设计还是我做错了什么?

我正在使用事件处理程序类 PatternMatchingEventHandler

event_handler = MediaFileHandler(ignore_directories=True) 
observer = Observer() 
observer.schedule(event_handler, path=directory, recursive=True) 
observer.start()
Run Code Online (Sandbox Code Playgroud)

如果这是正确的行为,我可以安全地忽略创建的事件吗?

python watchdog

4
推荐指数
1
解决办法
3549
查看次数