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):
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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment