Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dadf1e78 authored by Stefan Raspl's avatar Stefan Raspl Committed by Paolo Bonzini
Browse files

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: default avatarStefan Raspl <raspl@linux.vnet.ibm.com>
Reviewed-by: default avatarMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
parent 9fc0adfc
Loading
Loading
Loading
Loading
+17 −11
Original line number Original line Diff line number Diff line
@@ -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."""
    try:
        s = stats.get()
        s = stats.get()
        time.sleep(1)
        time.sleep(1)
        s = stats.get()
        s = stats.get()
        for key in sorted(s.keys()):
        for key in sorted(s.keys()):
            values = s[key]
            values = s[key]
            print '%-42s%10d%10d' % (key, values[0], values[1])
            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:
        try:
            time.sleep(1)
            time.sleep(1)
            if line % banner_repeat == 0:
            if line % banner_repeat == 0:
                banner()
                banner()
            statline()
            statline()
            line += 1
            line += 1
        except KeyboardInterrupt:
            break


def get_options():
def get_options():
    """Returns processed program arguments."""
    """Returns processed program arguments."""