Python Watchdog 实行对文件或目录的监控
来源:互联网 发布:软件项目验收程序 编辑:程序博客网 时间:2024/05/19 20:19
watchdog 库支持多平台,受到越来越多的关注。顾名思义,watchdog库就是对文件或者目录(event)来监控以及作出反应。我们对文件作出删除,生成,修改和移动时,event就代表你所做的行为传入到FileSystemEvent类进行处理,然后通过FileSystemEventHandler来作出反应。
FileSystemEvent(event)—>FileSystemEventHandler(event)
即:
- watchdog.event.Dir/FileDeletedEvent(event)**—>**self.on_deleted(event)
- watchdog.event.Dir/FileCreatedEvent(event)**—>**self.on_created(event)
- watchdog.event.Dir/FileModifiedEvent(event)**—>**self.on_modified(event)
- watchdog.event.Dir/FileMovedEvent(event)**—>**self.on_moved(event)
以上这些监控和改变均是通过watchdog.observers.Observer()来实现的。
以下为官方实例:
import sysimport timeimport loggingfrom watchdog.observers import Observerfrom watchdog.events import LoggingEventHandlerif __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()
0 0
- Python Watchdog 实行对文件或目录的监控
- python利用watchdog监控目录并上传到ftp
- python watchdog:监控文件系统事件的Python库
- python watchdog:监控文件系统事件的Python库
- python watchdog监控文件系统变动
- python监控文件或目录变化-实例,用paramiko远程监控文件夹变化
- python打开文件或目录的方法
- Python中获取某个用户对某个文件或目录的访问权限
- Python对目录、文件的操作
- Python对文件和目录的操作
- inotify-文件或目录监控
- python中文件变化监控-watchdog
- Python文件或目录操作的常用函数
- Python文件或目录操作的常用函数
- Python.h:没有那个文件或目录 错误的方法
- python 获取某个目录字段下的子目录或文件
- python返回指定目录下指定的文件或文件夹
- Android framework Watchdog的监控过程
- 动态规划经典问题:01背包
- 管理oracle企业管理数据库控制器
- 1019. 数字黑洞 (20)
- python numpy
- LeetCode121 Best Time to Buy and Sell Stock
- Python Watchdog 实行对文件或目录的监控
- Binder的应用层的核心类
- 人脸检测(二)
- Java入门-1-数据类型
- 项目中遇到的问题总结
- 推荐算法:协同过滤原理介绍
- Android手机接收不到UDP报文
- LeetCode122 Best Time to Buy and Sell Stock II
- MySQL增删改查基础