异步的inotify

inotip的Python项目详细描述


inotipy是linux
[`inotify(7)`(http://man7.org/linux/man-pages/man7/inotify.7.html)api的高级python包装器,
设计用于python 3.5或更高版本中的
[`asyncio`](https://docs.python.org/3/library/asyncio.html)事件循环
。这样,您就可以有效地监视一个或多个
文件或目录中的有趣事件,而无需
不断轮询文件系统。但是,请注意,如果事件
太厚和太快,内核可能会开始删除
它们,这将由设置了“in.q_overflow”位的事件向您报告。




对于更改:

import sys
import asyncio
import inotipy

loop=asyncio.get_event_loop()


paths_to_watch=[“test”];根据需要进行编辑

async def mainline():
watcher=inotipy.watcher.create()
watcher.watch(path,inotipy.in.all廑event s)
end for
while true:
event=await watcher.get()
sys.stdout.write(“get event:%s\n%repr(event))
end while
end mainline

loop.run廑until廑complete(mainline())

然后在另一个终端会话中
执行以下一系列命令行操作:

$echo hi>;test/f1
$mv test/f1 test/f2
$cat test/f2
$rm test/f2
$rmdir test

然后我们会看到脚本报告一个类似于这样的事件流:

got event:event(1,[<;创建时间:8>;]、0,'f1')
br/>获取事件:事件(1,[<;事件:5>;]、0,'f1')
获取事件:事件(1,[<;事件:1,[<;事件;修改:1>;]、0,'f1')
获取事件:事件:事件(1,[<;事件:事件:关闭时间:3>;]、0,'f1')
获取事件:事件(1,[<;事件:6>;]、2171855,'f1')
获取事件:事件:事件(1,[<;事件:事件:从:6>;]、2117185;中移动的事件:事件:事件:1,[>'f1')
获取事件:事件(1,[<;event'u bit.moveu-to:7>;]、217185,'f2')
get-event:event(1,[<;event'bit.open:5>;]、0,'f2')
get-event:event(1,[<;event'u bit.access:0>;]、0,'f2')
get-event:event(1,[<;event'u bit.close-nowrite:4>;]、0,'f2')
get-event:event(1,[<;event'lt;event-bit.delete:9<;event-bit.open:5>;]、0,'gt;gt;],0,“f2”)
获取事件:事件(1,[<;event_bit.delete_self:10>;]、0,”)
获取事件:事件(1,[<;event_bit.ignored:15>;]、0,”)

有关更详细的示例,
请参阅我的“inotipy示例”repo
([gitlab](https://gitlab.com/ldo/inotipy示例),
[github](https://github.com/ldo/inotipy示例))。

有更多可用功能:请参阅“inotify(7)”手册页
,当然还有“inotify.py”中的文档本身。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java需要64位jdk 1.5 for windows   eclipse运算符+对于参数类型java是未定义的。双,爪哇。双人   未下载文件扩展名为的java文件   java不支持带有POST的媒体类型   从动态创建的多个EditText读取文本时发生java错误   java无法为同一xpath单击多个按钮   如何在Java中动态格式化字符串   java Android Clear Middle活动   多线程Java内存模型volatile和x86   git在Java中通过Jgit忽略文件或文件夹   java“决策无法区分输入的备选方案1、2…”   子类的javajpa继承   java需要弄清楚如何操作mutator来弄清楚一个类,教授说,我对如何操作感到困惑   java如何使用JDBC将数据从文件复制到PostgreSQL?