tools/kvm_stat: handle SIGINT in log and batch modes

SIGINT causes ugly unhandled exceptions in log and batch mode, which we
prevent by catching the exceptions accordingly.

Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
This commit is contained in:
Stefan Raspl 2017-03-10 13:40:02 +01:00 коммит произвёл Paolo Bonzini
Родитель 9fc0adfc42
Коммит dadf1e7839
1 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -969,12 +969,15 @@ class Tui(object):
def batch(stats): def batch(stats):
"""Prints statistics in a key, value format.""" """Prints statistics in a key, value format."""
s = stats.get() try:
time.sleep(1) s = stats.get()
s = stats.get() time.sleep(1)
for key in sorted(s.keys()): s = stats.get()
values = s[key] for key in sorted(s.keys()):
print '%-42s%10d%10d' % (key, values[0], values[1]) values = s[key]
print '%-42s%10d%10d' % (key, values[0], values[1])
except KeyboardInterrupt:
pass
def log(stats): def log(stats):
"""Prints statistics as reiterating key block, multiple value blocks.""" """Prints statistics as reiterating key block, multiple value blocks."""
@ -991,11 +994,14 @@ def log(stats):
line = 0 line = 0
banner_repeat = 20 banner_repeat = 20
while True: while True:
time.sleep(1) try:
if line % banner_repeat == 0: time.sleep(1)
banner() if line % banner_repeat == 0:
statline() banner()
line += 1 statline()
line += 1
except KeyboardInterrupt:
break
def get_options(): def get_options():
"""Returns processed program arguments.""" """Returns processed program arguments."""