From b2f1982bac2fee602e7d2151a29e4c8ef14b6844 Mon Sep 17 00:00:00 2001 From: zora tung Date: Wed, 13 Apr 2016 18:35:23 -0400 Subject: [PATCH 1/2] Only sleep if a line was not read If the process writing to the tailed file writes at more than 1 line per second, the reader will never catch up. This should fix the problem. --- tail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tail.py b/tail.py index c9e4fc2..24f69d0 100644 --- a/tail.py +++ b/tail.py @@ -54,9 +54,9 @@ def follow(self, s=1): line = file_.readline() if not line: file_.seek(curr_position) + time.sleep(s) else: self.callback(line) - time.sleep(s) def register_callback(self, func): ''' Overrides default callback function to provided function. ''' From 88f961dcedff0e73d1ee5621fc4bb6a818133822 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Mon, 27 Sep 2021 07:26:04 +1000 Subject: [PATCH 2/2] docs: fix simple typo, registerd -> registered There is a small typo in tail.py. Should read `registered` rather than `registerd`. --- tail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tail.py b/tail.py index 24f69d0..028cfc2 100644 --- a/tail.py +++ b/tail.py @@ -12,7 +12,7 @@ t = tail.Tail('file-to-be-followed') # Register a callback function to be called when a new line is found in the followed file. - # If no callback function is registerd, new lines would be printed to standard out. + # If no callback function is registered, new lines would be printed to standard out. t.register_callback(callback_function) # Follow the file with 5 seconds as sleep time between iterations.