Skip to content
Snippets Groups Projects
Commit a77b078f authored by Sven Mäder's avatar Sven Mäder :speech_balloon:
Browse files

Add exception handling

parent c0c347cf
No related branches found
No related tags found
1 merge request!12Deltalogparse
...@@ -113,15 +113,22 @@ def tail_file(log_file): ...@@ -113,15 +113,22 @@ def tail_file(log_file):
fin = subprocess.Popen(['tail', '-F', log_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) fin = subprocess.Popen(['tail', '-F', log_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
poll = select.poll() poll = select.poll()
poll.register(fin.stdout) poll.register(fin.stdout)
while True:
start_time = time.perf_counter()
if poll.poll(1): try:
line = fin.stdout.readline().decode('utf-8') while True:
parse(line) 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): def read_file(log_file):
...@@ -129,19 +136,29 @@ def read_file(log_file): ...@@ -129,19 +136,29 @@ def read_file(log_file):
with open(log_file, 'r') as fin: with open(log_file, 'r') as fin:
while True: while True:
line = fin.readline() line = fin.readline()
if not line: if not line:
break break
parse(line) parse(line)
def read_stdin(): def read_stdin():
"""Read from stdin""" """Read from stdin"""
fin = sys.stdin fin = sys.stdin
while True:
line = fin.readline() try:
if not line: while True:
break line = fin.readline()
parse(line)
if not line:
break
parse(line)
except KeyboardInterrupt:
sys.stdout.flush()
pass
def main(): def main():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment