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)
评论列表
文章目录