Commit d0c31819 authored by Brenden Blanco's avatar Brenden Blanco

Make KeyboardInterrupt catch more aggressive

Fixes: #186
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 0b904997
...@@ -653,6 +653,7 @@ class BPF(object): ...@@ -653,6 +653,7 @@ class BPF(object):
fields (task, pid, cpu, flags, timestamp, msg) or None if no fields (task, pid, cpu, flags, timestamp, msg) or None if no
line was read (nonblocking=True) line was read (nonblocking=True)
""" """
try:
while True: while True:
line = self.trace_readline(nonblocking) line = self.trace_readline(nonblocking)
if not line and nonblocking: return (None,) * 6 if not line and nonblocking: return (None,) * 6
...@@ -665,6 +666,8 @@ class BPF(object): ...@@ -665,6 +666,8 @@ class BPF(object):
cpu = cpu[1:-1] cpu = cpu[1:-1]
msg = line[ts_end + 4:] msg = line[ts_end + 4:]
return (task, int(pid), int(cpu), flags, float(ts), msg) return (task, int(pid), int(cpu), flags, float(ts), msg)
except KeyboardInterrupt:
exit()
def trace_readline(self, nonblocking=False): def trace_readline(self, nonblocking=False):
"""trace_readline(nonblocking=False) """trace_readline(nonblocking=False)
...@@ -693,6 +696,7 @@ class BPF(object): ...@@ -693,6 +696,7 @@ class BPF(object):
example: trace_print(fmt="pid {1}, msg = {5}") example: trace_print(fmt="pid {1}, msg = {5}")
""" """
try:
while True: while True:
if fmt: if fmt:
fields = self.trace_fields(nonblocking=False) fields = self.trace_fields(nonblocking=False)
...@@ -702,6 +706,8 @@ class BPF(object): ...@@ -702,6 +706,8 @@ class BPF(object):
line = self.trace_readline(nonblocking=False) line = self.trace_readline(nonblocking=False)
print(line) print(line)
sys.stdout.flush() sys.stdout.flush()
except KeyboardInterrupt:
exit()
@staticmethod @staticmethod
def _load_kallsyms(): def _load_kallsyms():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment