From 06c23d80e8acae27825e458c298e52f736015f90 Mon Sep 17 00:00:00 2001 From: Maodouzi Date: Sun, 14 Sep 2014 10:53:39 +0800 Subject: [PATCH] Add a improvement in Tail.follow Callback will impact to all the new-added lines once time.sleep ended, rather than line by line according to the timer. --- tail.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tail.py b/tail.py index c9e4fc2..2821681 100644 --- a/tail.py +++ b/tail.py @@ -51,11 +51,12 @@ def follow(self, s=1): file_.seek(0,2) while True: curr_position = file_.tell() - line = file_.readline() - if not line: - file_.seek(curr_position) - else: - self.callback(line) + file_.seek(0,2) + end_position = file_.tell() + file_.seek(curr_position) + if curr_position != end_position: + for line in file_: + self.callback(line) time.sleep(s) def register_callback(self, func):