ztail.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:csirtg-smrt-py 作者: csirtgadgets 项目源码 文件源码
def tail(fn):
    """Like tail -F """
    inode = stat_inode(fn)
    f = open_wait(fn)
    f.seek(0, 2)

    # Has the file inode changed
    changed = False
    while True:
        l = f.readline()
        if l:
            yield l
        elif changed:
            f.close()
            f = open_wait(fn)
            inode = os.fstat(f.fileno()).st_ino
            changed = False
        elif stat_inode(fn) != inode:
            #set changed to true, but then keep trying to read from the file to
            #check to see if it was written to after it was rotated.
            changed = True
        else:
            time.sleep(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号