python代码的tail-f功能。跟踪文件追加和截断。

tailf的Python项目详细描述


尾翼

tail -fpython代码的功能。跟踪文件追加和 截断。

支持python3.6+。

示例

pip install tailf==0.2.5
importtailfimporttimewithtailf.Tail(filename)astail:whileTrue:foreventintail:ifisinstance(event,bytes):print(event.decode("utf-8"),end='')elifeventistailf.Truncated:print("File was truncated")else:assertFalse,"unreachable"# currently. more events may be introduced latertime.sleep(0.01)# save CPU cycles
# this example requires python3.7importasyncioimporttailfasyncdefmain():withtailf.Tail(filename)astail:whileTrue:event=awaittail.wait_event()ifisinstance(event,bytes):print(event.decode("utf-8"),end='')elifeventistailf.Truncated:print("File was truncated")else:assertFalse,"unreachable"# currently. more events may be introduced laterasyncio.run(main())

限制

  • 截断检测通常是不可靠的。它主要由 文件大小减小,这有时可能不可靠。当一个文件 变大很少被截断,这就足够了。

  • 异步跟踪在计时器事件(当前为0.01秒)时完成。 inotify支持可以在linux上解决这个问题。请随意提出其他建议 解决。

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

推荐PyPI第三方库


热门话题
java用级数求双精度的平方根   java游戏开发:如何限制FPS?   使用Hibernate时,java无法填充jcombo框   java JPA Eclipselink继承:更新不起作用   java facebook会话未打开   将自定义maven插件从本地jar安装到具有依赖项的本地存储库中   java JPA如何将过滤器应用于EJB标准查询   java在Eclipse中处于非活动状态后执行操作   java顺序流与并行流更改为中间和终端操作引入的顺序   java通过映射字段名添加自动前缀   java属性“xmlns:?”必须为“bean”类型的元素声明   java/processing返回ArrayList抛出:此方法必须返回ArrayList类型的结果   java在Google Appengine上使用JDO交换列表中的两个元素   java将迭代器转换为lambda   java试图从RAD 7.5运行JUnit 4.10测试时出现异常