From patchwork Mon Jun 5 18:59:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 771395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3whPTC0LbZz9s7p for ; Tue, 6 Jun 2017 05:07:26 +1000 (AEST) Received: from localhost ([::1]:34749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHxLY-0007Zq-Iw for incoming@patchwork.ozlabs.org; Mon, 05 Jun 2017 15:07:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHxEM-00020i-Ig for qemu-devel@nongnu.org; Mon, 05 Jun 2017 14:59:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHxEJ-00086s-Cy for qemu-devel@nongnu.org; Mon, 05 Jun 2017 14:59:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dHxEJ-00086V-7b for qemu-devel@nongnu.org; Mon, 05 Jun 2017 14:59:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31B3DC04B929; Mon, 5 Jun 2017 18:59:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 31B3DC04B929 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 31B3DC04B929 Received: from localhost (ovpn-116-6.gru2.redhat.com [10.97.116.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E1A486E0D; Mon, 5 Jun 2017 18:59:51 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , Stefan Hajnoczi Date: Mon, 5 Jun 2017 15:59:25 -0300 Message-Id: <20170605185927.12111-9-ehabkost@redhat.com> In-Reply-To: <20170605185927.12111-1-ehabkost@redhat.com> References: <20170605185927.12111-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 05 Jun 2017 18:59:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/10] qemu.py: Don't set _popen=None on error/shutdown X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Keep the Popen object around to we can query its exit code later. To keep the existing 'self._popen is None' checks working, add a is_running() method, that will check if the process is still running. Signed-off-by: Eduardo Habkost Message-Id: <20170526181200.17227-2-ehabkost@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Eduardo Habkost --- scripts/qemu.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 6d1b6230b7..16934f1e02 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -85,8 +85,11 @@ class QEMUMachine(object): return raise + def is_running(self): + return self._popen and (self._popen.returncode is None) + def get_pid(self): - if not self._popen: + if not self.is_running(): return None return self._popen.pid @@ -128,16 +131,16 @@ class QEMUMachine(object): stderr=subprocess.STDOUT, shell=False) self._post_launch() except: - if self._popen: + if self.is_running(): self._popen.kill() + self._popen.wait() self._load_io_log() self._post_shutdown() - self._popen = None raise def shutdown(self): '''Terminate the VM and clean up''' - if not self._popen is None: + if self.is_running(): try: self._qmp.cmd('quit') self._qmp.close() @@ -149,7 +152,6 @@ class QEMUMachine(object): sys.stderr.write('qemu received signal %i: %s\n' % (-exitcode, ' '.join(self._args))) self._load_io_log() self._post_shutdown() - self._popen = None underscore_to_dash = string.maketrans('_', '-') def qmp(self, cmd, conv_keys=True, **args):