From nobody Sun Feb 8 21:16:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580825567653330.88302953139817; Tue, 4 Feb 2020 06:12:47 -0800 (PST) Received: from localhost ([::1]:59304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyywX-0005Dn-IT for importer@patchew.org; Tue, 04 Feb 2020 09:12:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44374) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyvP-0003tt-U7 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyyvO-0001G7-Q9 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:35 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30649 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyyvO-0001AN-Lj for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:34 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-129-4KwxMjsEMyqVegknD60w2A-1; Tue, 04 Feb 2020 09:11:30 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E20C910CE786 for ; Tue, 4 Feb 2020 14:11:29 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E70287792B; Tue, 4 Feb 2020 14:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580825493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ycinBl/JjBnbdyOHEMoiuJ5oJmXCzRVWDSK/n39niuE=; b=eWs2ixQN7GL82q4ZSkpM1mgRbhJ5jUztBM/GpF5OADUTZxR3uYaxQhGLz/0Bb6ghZ/X7Hu nVbUzplT9Kc63Fj/9+j7HFyq9T1quBbWCkbK1J11QiJ+FI3RIAZ8NVCtLJnQgUVp/Nscdg Ic+1ZBri6lud4B7tOiMMHM6sWKwrsnY= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 1/5] python/qemu: qmp: Replace socket.error with OSError Date: Tue, 4 Feb 2020 11:11:07 -0300 Message-Id: <20200204141111.3207-2-wainersm@redhat.com> In-Reply-To: <20200204141111.3207-1-wainersm@redhat.com> References: <20200204141111.3207-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 4KwxMjsEMyqVegknD60w2A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com, philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The socket.error is deprecated from Python 3.3, instead it is made a link to OSError. This change replaces the occurences of socket.error with OSError. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow --- python/qemu/qmp.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 5c8cf6a056..8c6c9847d0 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -47,7 +47,7 @@ class QEMUMonitorProtocol(object): or a tuple in the form ( address, port ) for a TCP connection @param server: server mode listens on the socket (bool) - @raise socket.error on socket connection errors + @raise OSError on socket connection errors @note No connection is established, this is done by the connect() = or accept() methods """ @@ -107,8 +107,8 @@ class QEMUMonitorProtocol(object): self.__sock.setblocking(0) try: self.__json_read() - except socket.error as err: - if err[0] =3D=3D errno.EAGAIN: + except OSError as err: + if err.errno =3D=3D errno.EAGAIN: # No data available pass self.__sock.setblocking(1) @@ -133,7 +133,7 @@ class QEMUMonitorProtocol(object): Connect to the QMP Monitor and perform capabilities negotiation. =20 @return QMP greeting dict - @raise socket.error on socket connection errors + @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities """ @@ -147,7 +147,7 @@ class QEMUMonitorProtocol(object): Await connection from QMP Monitor and perform capabilities negotia= tion. =20 @return QMP greeting dict - @raise socket.error on socket connection errors + @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities """ @@ -167,10 +167,10 @@ class QEMUMonitorProtocol(object): self.logger.debug(">>> %s", qmp_cmd) try: self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) - except socket.error as err: - if err[0] =3D=3D errno.EPIPE: + except OSError as err: + if err.errno =3D=3D errno.EPIPE: return - raise socket.error(err) + raise err resp =3D self.__json_read() self.logger.debug("<<< %s", resp) return resp --=20 2.23.0 From nobody Sun Feb 8 21:16:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580825568523606.7909519321926; Tue, 4 Feb 2020 06:12:48 -0800 (PST) Received: from localhost ([::1]:59306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyywZ-0005HK-1G for importer@patchew.org; Tue, 04 Feb 2020 09:12:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44445) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyvS-0003vn-DM for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyyvR-0001Ws-0n for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:38 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54963 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyyvQ-0001UO-Se for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:36 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-285-Pcg5QJv4MnWST9L9vkhSCQ-1; Tue, 04 Feb 2020 09:11:34 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 11F9C800D54 for ; Tue, 4 Feb 2020 14:11:34 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCABA867EF; Tue, 4 Feb 2020 14:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580825496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+edobARfRNWiQFWJydKgvPKBP+opixAnGIVaO9yES0I=; b=ReknmoMuo+cImImj/+HlNrCUbBd2B5qUMJVJ1iR4fo2ZRCtR7oLq+i+XdACUOQzvNbxoo2 WNnaEJI7aUrCCzaR9DSHpiJ1sBrxUlrcvhbVCCz5vh5J0mncPtHyZtEmKM7E0zaLz9t1s/ Eelt0b8IzwBMGyLWHcMkv/bWCWtoC9E= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 2/5] python/qemu: Delint the qmp module Date: Tue, 4 Feb 2020 11:11:08 -0300 Message-Id: <20200204141111.3207-3-wainersm@redhat.com> In-Reply-To: <20200204141111.3207-1-wainersm@redhat.com> References: <20200204141111.3207-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: Pcg5QJv4MnWST9L9vkhSCQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com, philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This clean up the pylint-3 report on qmp: ************* Module qemu.qmp python/qemu/qmp.py:1:0: C0111: Missing module docstring (missing-docstring) python/qemu/qmp.py:17:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:21:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:25:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:29:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:33:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:33:0: R0205: Class 'QEMUMonitorProtocol' inherits from o= bject, can be safely removed from bases in python3 (useless-object-inherita= nce) python/qemu/qmp.py:80:4: R1710: Either all return statements in a function = should return an expression, or none of them should. (inconsistent-return-s= tatements) python/qemu/qmp.py:131:4: R1710: Either all return statements in a function= should return an expression, or none of them should. (inconsistent-return-= statements) python/qemu/qmp.py:159:4: R1710: Either all return statements in a function= should return an expression, or none of them should. (inconsistent-return-= statements) python/qemu/qmp.py:245:4: C0111: Missing method docstring (missing-docstrin= g) python/qemu/qmp.py:249:4: C0111: Missing method docstring (missing-docstrin= g) python/qemu/qmp.py:252:4: C0111: Missing method docstring (missing-docstrin= g) python/qemu/qmp.py:255:4: C0111: Missing method docstring (missing-docstrin= g) Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow --- python/qemu/qmp.py | 51 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 8c6c9847d0..f4e04a6683 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -1,5 +1,4 @@ -# QEMU Monitor Protocol Python class -# +""" QEMU Monitor Protocol Python class """ # Copyright (C) 2009, 2010 Red Hat Inc. # # Authors: @@ -15,22 +14,34 @@ import logging =20 =20 class QMPError(Exception): - pass + """ + QMP base exception + """ =20 =20 class QMPConnectError(QMPError): - pass + """ + QMP connection exception + """ =20 =20 class QMPCapabilitiesError(QMPError): - pass + """ + QMP negotiate capabilities exception + """ =20 =20 class QMPTimeoutError(QMPError): - pass + """ + QMP timeout exception + """ =20 =20 -class QEMUMonitorProtocol(object): +class QEMUMonitorProtocol: + """ + Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and = then + allow to handle commands and events. + """ =20 #: Logger object for debugging messages logger =3D logging.getLogger('QMP') @@ -81,7 +92,7 @@ class QEMUMonitorProtocol(object): while True: data =3D self.__sockfile.readline() if not data: - return + return None resp =3D json.loads(data) if 'event' in resp: self.logger.debug("<<< %s", resp) @@ -132,7 +143,7 @@ class QEMUMonitorProtocol(object): """ Connect to the QMP Monitor and perform capabilities negotiation. =20 - @return QMP greeting dict + @return QMP greeting dict, or None if negotiate is false @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities @@ -141,6 +152,7 @@ class QEMUMonitorProtocol(object): self.__sockfile =3D self.__sock.makefile() if negotiate: return self.__negotiate_capabilities() + return None =20 def accept(self): """ @@ -169,7 +181,7 @@ class QEMUMonitorProtocol(object): self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) except OSError as err: if err.errno =3D=3D errno.EPIPE: - return + return None raise err resp =3D self.__json_read() self.logger.debug("<<< %s", resp) @@ -243,14 +255,33 @@ class QEMUMonitorProtocol(object): self.__events =3D [] =20 def close(self): + """ + Close the socket and socket file. + """ self.__sock.close() self.__sockfile.close() =20 def settimeout(self, timeout): + """ + Set the socket timeout. + + @param timeout (float): timeout in seconds, or None. + @note This is a wrap around socket.settimeout + """ self.__sock.settimeout(timeout) =20 def get_sock_fd(self): + """ + Get the socket file descriptor. + + @return The file descriptor number. + """ return self.__sock.fileno() =20 def is_scm_available(self): + """ + Check if the socket allows for SCM_RIGHTS. + + @return True if SCM_RIGHTS is available, otherwise False. + """ return self.__sock.family =3D=3D socket.AF_UNIX --=20 2.23.0 From nobody Sun Feb 8 21:16:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580825599850553.3492270397132; Tue, 4 Feb 2020 06:13:19 -0800 (PST) Received: from localhost ([::1]:59318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyx4-0006X2-5Y for importer@patchew.org; Tue, 04 Feb 2020 09:13:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45128) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyvs-0004mQ-N5 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:12:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyyvr-0004Ve-Do for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:12:04 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43355 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyyvr-0004Qi-96 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:12:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-e2ozRJS0N1WO63VWwEPGdQ-1; Tue, 04 Feb 2020 09:11:44 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B2AB805730 for ; Tue, 4 Feb 2020 14:11:43 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EBB47792B; Tue, 4 Feb 2020 14:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580825522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=636WZS6nu8LPjvMeEyhXKmDiaWYQN2+N9JeCFGjJTuM=; b=F+Ix4zLY/4+NPN+ZK+0GqzkG5noAdcYKZ7R+s8NH6D6DYLs9ImJN7YONOzbc7i15lwdM5N WJcaSH6hmrMiMkLo8woQAJ0SUEmPIS46AIYz6QgYOvhJ/DpnToC2Q0zI54CBQbY1devv0I 6UffXx6t3w3lskbqfrq5M6I8YILAaB8= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 3/5] python/qemu: qmp: Make accept()'s timeout configurable Date: Tue, 4 Feb 2020 11:11:09 -0300 Message-Id: <20200204141111.3207-4-wainersm@redhat.com> In-Reply-To: <20200204141111.3207-1-wainersm@redhat.com> References: <20200204141111.3207-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: e2ozRJS0N1WO63VWwEPGdQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com, philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently the timeout of QEMUMonitorProtocol.accept() is hard-coded to 15.0 seconds. This added the parameter `timeout` so the value can be configured by the user. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: John Snow --- python/qemu/qmp.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index f4e04a6683..0e07d80e2a 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -154,16 +154,23 @@ class QEMUMonitorProtocol: return self.__negotiate_capabilities() return None =20 - def accept(self): + def accept(self, timeout=3D15.0): """ Await connection from QMP Monitor and perform capabilities negotia= tion. =20 + @param timeout: timeout in seconds (nonnegative float number, or + None). The value passed will set the behavior of t= he + underneath QMP socket as described in [1]. Default= value + is set to 15.0. @return QMP greeting dict @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities + + [1] + https://docs.python.org/3/library/socket.html#socket.socket.settim= eout """ - self.__sock.settimeout(15) + self.__sock.settimeout(timeout) self.__sock, _ =3D self.__sock.accept() self.__sockfile =3D self.__sock.makefile() return self.__negotiate_capabilities() --=20 2.23.0 From nobody Sun Feb 8 21:16:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580825747440376.859555301289; Tue, 4 Feb 2020 06:15:47 -0800 (PST) Received: from localhost ([::1]:59364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyzS-0001as-BW for importer@patchew.org; Tue, 04 Feb 2020 09:15:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44833) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyvh-0004Qk-RT for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyyvg-0003Hw-Qz for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:53 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:44287 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyyvg-0003Ev-M1 for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:52 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-V15dktj3P4alV0bWA-cEzw-1; Tue, 04 Feb 2020 09:11:48 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85AFF800D5C for ; Tue, 4 Feb 2020 14:11:47 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 506DB7792B; Tue, 4 Feb 2020 14:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580825512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fJY9D1M44o9wctAPTFwalgRtHn4l/+HNnLvKeOIovgQ=; b=YhcXbd6tE3HPyRtLTxQ+18GH68m46LW2jr3yRxvKtd5rt/Gm2t7mbqtYCqBdJd/qmB1VRg pFwBGEvAX9QINVPvhJveJE1daSxvaEssRzCbFy5Q+0bDsgIfhiDgD6Igp/XqAanmV7Nhvx An44cqM4GgULzdGNgOLtNmzSGzxlbPU= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 4/5] python/qemu: qmp: Make QEMUMonitorProtocol a context manager Date: Tue, 4 Feb 2020 11:11:10 -0300 Message-Id: <20200204141111.3207-5-wainersm@redhat.com> In-Reply-To: <20200204141111.3207-1-wainersm@redhat.com> References: <20200204141111.3207-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: V15dktj3P4alV0bWA-cEzw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com, philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This implement the __enter__ and __exit__ functions on QEMUMonitorProtocol class so that it can be used on 'with' statement and the resources will be free up on block end: with QEMUMonitorProtocol(socket_path) as qmp: qmp.connect() qmp.command('query-status') Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow --- python/qemu/qmp.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 0e07d80e2a..486a566da0 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -139,6 +139,15 @@ class QEMUMonitorProtocol: raise QMPConnectError("Error while reading from socket") self.__sock.settimeout(None) =20 + def __enter__(self): + # Implement context manager enter function. + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + # Implement context manager exit function. + self.close() + return False + def connect(self, negotiate=3DTrue): """ Connect to the QMP Monitor and perform capabilities negotiation. @@ -265,8 +274,10 @@ class QEMUMonitorProtocol: """ Close the socket and socket file. """ - self.__sock.close() - self.__sockfile.close() + if self.__sock: + self.__sock.close() + if self.__sockfile: + self.__sockfile.close() =20 def settimeout(self, timeout): """ --=20 2.23.0 From nobody Sun Feb 8 21:16:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580825821724391.3857045995602; Tue, 4 Feb 2020 06:17:01 -0800 (PST) Received: from localhost ([::1]:59386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyz0e-0002XE-Dk for importer@patchew.org; Tue, 04 Feb 2020 09:17:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44889) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyyvj-0004Up-MN for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyyvi-0003Xr-LO for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:55 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:24147 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyyvi-0003U8-Go for qemu-devel@nongnu.org; Tue, 04 Feb 2020 09:11:54 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-21-Wpc5lCfoOYSm_RXUhGwc3w-1; Tue, 04 Feb 2020 09:11:52 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2D6218A6EC0 for ; Tue, 4 Feb 2020 14:11:51 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-4.gru2.redhat.com [10.97.116.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CDD2842A9; Tue, 4 Feb 2020 14:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580825514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJLhoD6eH1RO0HHewTMQIjJx6ctfWM30l45DwMD9bdI=; b=bdyH9rbjoV3EgeDjrcdkjWH8M2nmJQUACCGGt3bd9r6kHzclOM8AZ7Ke3SndUkVcaIGDzD d+LQ5owvvnfwzy7srGYFGtU/9uLFqYuWeyHF4aM2saRFxMcM+Ki5zfejz6tzeI/t1IlCcy MF/fNTMA3eUyzy8J1mNnqier5JPSYj8= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 5/5] python/qemu: qmp: Remove unnused attributes Date: Tue, 4 Feb 2020 11:11:11 -0300 Message-Id: <20200204141111.3207-6-wainersm@redhat.com> In-Reply-To: <20200204141111.3207-1-wainersm@redhat.com> References: <20200204141111.3207-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: Wpc5lCfoOYSm_RXUhGwc3w-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsnow@redhat.com, philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The `error` and `timeout` attributes in QEMUMonitorProtocol are not used, so this delete them. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow --- python/qemu/qmp.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 486a566da0..4b9a362240 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -45,10 +45,6 @@ class QEMUMonitorProtocol: =20 #: Logger object for debugging messages logger =3D logging.getLogger('QMP') - #: Socket's error class - error =3D socket.error - #: Socket's timeout - timeout =3D socket.timeout =20 def __init__(self, address, server=3DFalse): """ --=20 2.23.0