From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [PATCH v2 03/17] tools/kvm_stat: handle SIGINT in log and batch modes Date: Wed, 15 Mar 2017 22:54:40 +0100 Message-ID: <20170315215440.GJ14081@potion> References: <20170310124016.96319-1-raspl@linux.vnet.ibm.com> <20170310124016.96319-4-raspl@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, pbonzini@redhat.com, frankja@linux.vnet.ibm.com To: Stefan Raspl Return-path: Received: from mx1.redhat.com ([209.132.183.28]:59568 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754102AbdCOVyt (ORCPT ); Wed, 15 Mar 2017 17:54:49 -0400 Content-Disposition: inline In-Reply-To: <20170310124016.96319-4-raspl@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: 2017-03-10 13:40+0100, Stefan Raspl: > SIGINT causes ugly unhandled exceptions in log and batch mode, which we > prevent by catching the exceptions accordingly. > > Signed-off-by: Stefan Raspl > Reviewed-by: Marc Hartmayer > --- The interactive mode also gets Exception KeyboardInterrupt in > ignored If you press ^C twice fast :) > tools/kvm/kvm_stat/kvm_stat | 28 +++++++++++++++++----------- > 1 file changed, 17 insertions(+), 11 deletions(-) > > diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat > index ef47ad7..14536c0 100755 > --- a/tools/kvm/kvm_stat/kvm_stat > +++ b/tools/kvm/kvm_stat/kvm_stat > @@ -969,12 +969,15 @@ class Tui(object): > > def batch(stats): > """Prints statistics in a key, value format.""" > - s = stats.get() > - time.sleep(1) > - s = stats.get() > - for key in sorted(s.keys()): > - values = s[key] > - print '%-42s%10d%10d' % (key, values[0], values[1]) > + try: > + s = stats.get() > + time.sleep(1) > + s = stats.get() > + for key in sorted(s.keys()): > + values = s[key] > + print '%-42s%10d%10d' % (key, values[0], values[1]) > + except KeyboardInterrupt: > + pass > > def log(stats): > """Prints statistics as reiterating key block, multiple value blocks.""" > @@ -991,11 +994,14 @@ def log(stats): > line = 0 > banner_repeat = 20 > while True: > - time.sleep(1) > - if line % banner_repeat == 0: > - banner() > - statline() > - line += 1 > + try: > + time.sleep(1) > + if line % banner_repeat == 0: > + banner() > + statline() > + line += 1 > + except KeyboardInterrupt: > + break > > def get_options(): > """Returns processed program arguments.""" > -- > 2.8.4 >