watchdog 监视文件系统事件
watchdog简介
watchdog,Python的第三方库。 watchdog可用于监视文件系统事件,是Python API和shell实用程序。
watchdog应用实例
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 '.'
logging.info(f'start watching directory {path!r}')
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
finally:
observer.stop()
observer.join()
watchdog Github统计数据
Apache-2.0
Github 6k stars
watchdog安装命令
python -m pip install -U watchdog
Python版本要求
Works on 3.6+. If you want to use Python 2.6, you should stick with watchdog < 0.10.0. If you want to use Python 2.7, 3.4 or 3.5, you should stick with watchdog < 1.0.0.
watchdog文档
Github:watchdog
Documentation:watchdog
免责声明:内容编辑自网络,仅供参考,不保证正确性,不作任何决策依据!!以上数据皆截止于博文的写稿日期。