关注此帖:Python - Reading chunks and break if there is no lines
我被告知这段代码已经一次读取大量的行:
file = open('logFile.txt', 'r')
count = 0
while 1:
where = file.tell()
for line in file:
if not line:
count = count + 1
if count >= 10:
break
time.sleep(1)
file.seek(where)
else:
try:
#process line
如果是这样,那么脚本如何检查一段时间内是否没有新行,结束for循环并继续脚本?我计算了一段时间,但这不起作用