读取动态更新的日志文件
def read_file(filename, content, times):
"""
统计动态更新的文件中指定内容出现次数
:param filename: 文件名
:param content: 匹配内容
:param times: 匹配次数
:return:
"""
count = 0
with open(filename, 'r') as fp:
while True:
flag = fp.tell()
line = fp.readline()
if not line:
time.sleep(1)
fp.seek(flag)
else:
# print(line)
if re.search(content, line):
count += 1
if count == times:
break