diff --git a/bin/deltalogcat.py b/bin/deltalogcat.py index 47aa1e43f2d61835575b619824541431b3e061e6..267bdf23ad32412e96070aaed950c215b513ad28 100755 --- a/bin/deltalogcat.py +++ b/bin/deltalogcat.py @@ -113,15 +113,22 @@ def tail_file(log_file): fin = subprocess.Popen(['tail', '-F', log_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) poll = select.poll() poll.register(fin.stdout) - - while True: - start_time = time.perf_counter() - if poll.poll(1): - line = fin.stdout.readline().decode('utf-8') - parse(line) + try: + while True: + start_time = time.perf_counter() + + if poll.poll(1): + line = fin.stdout.readline().decode('utf-8') + + parse(line) + + sleep(start_time) + + except KeyboardInterrupt: + sys.stdout.flush() + pass - sleep(start_time) def read_file(log_file): @@ -129,19 +136,29 @@ def read_file(log_file): with open(log_file, 'r') as fin: while True: line = fin.readline() + if not line: break + parse(line) def read_stdin(): """Read from stdin""" fin = sys.stdin - while True: - line = fin.readline() - if not line: - break - parse(line) + + try: + while True: + line = fin.readline() + + if not line: + break + + parse(line) + + except KeyboardInterrupt: + sys.stdout.flush() + pass def main():