• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python中使用Inotify监控文件实例

Python中使用Inotify监控文件实例

作者:junjie 字体:[增加 减小] 来源:互联网

junjie 通过本文主要向大家介绍了python inotify,inotify,rsync inotify,inotify tools,linux inotify等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Inotify地址:访问

# -*- coding:utf-8 -*-

import os
import pyinotify
from functions import *

WATCH_PATH = '' #监控目录

if not WATCH_PATH:
  wlog('Error',"The WATCH_PATH setting MUST be set.")
  sys.exit()
else:
  if os.path.exists(WATCH_PATH):
    wlog('Watch status','Found watch path: path=%s.' % (WATCH_PATH))
  else:
    wlog('Error','The watch path NOT exists, watching stop now: path=%s.' % (WATCH_PATH))
    sys.exit()

class OnIOHandler(pyinotify.ProcessEvent):
  def process_IN_CREATE(self, event):
    wlog('Action',"create file: %s " % os.path.join(event.path,event.name))

  def process_IN_DELETE(self, event):
    wlog('Action',"delete file: %s " % os.path.join(event.path,event.name))

  def process_IN_MODIFY(self, event):
    wlog('Action',"modify file: %s " % os.path.join(event.path,event.name))

def auto_compile(path = '.'):
  wm = pyinotify.WatchManager()
  mask = pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_MODIFY
  notifier = pyinotify.ThreadedNotifier(wm, OnIOHandler())
  notifier.start()
  wm.add_watch(path, mask,rec = True,auto_add = True)
  wlog('Start Watch','Start monitoring %s' % path)
  while True:
    try:
      notifier.process_events()
      if notifier.check_events():
        notifier.read_events()
    except KeyboardInterrupt:
      notifier.stop()
      break

if __name__ == "__main__":
   auto_compile(WATCH_PATH)
</div>

</div>

您可能想查找下面的文章:

  • Python中使用Inotify监控文件实例

相关文章

  • python实现2048小游戏
  • Python抓取淘宝下拉框关键词的方法
  • python实现simhash算法实例
  • Python装饰器入门学习教程(九步学习)
  • 使用Python生成随机密码的示例分享
  • Python新手实现2048小游戏
  • Python实现的百度站长自动URL提交小工具
  • python基于queue和threading实现多线程下载实例
  • python在Windows下安装setuptools(easy_install工具)步骤详解
  • Python实现删除Android工程中的冗余字符串

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 9种python web 程序的部署方式小结
    • Python常用的内置序列结构(列表、元组、字典)学习笔记
    • 编写简单的Python程序来判断文本的语种
    • 使用Python编写类UNIX系统的命令行工具的教程
    • Django中实现一个高性能计数器(Counter)实例
    • Python基于DES算法加密解密实例
    • Java Web开发过程中登陆模块的验证码的实现方式总结
    • python引用DLL文件的方法
    • 提升Python程序运行效率的6个方法
    • 通过数据库向Django模型添加字段的示例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有