异步的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”中的文档本身。
[`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”中的文档本身。