From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPZz4-0001cj-2a for qemu-devel@nongnu.org; Thu, 26 May 2011 08:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QPZz3-0004qA-20 for qemu-devel@nongnu.org; Thu, 26 May 2011 08:48:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40413) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QPZz2-0004p8-Ob for qemu-devel@nongnu.org; Thu, 26 May 2011 08:48:13 -0400 Date: Thu, 26 May 2011 09:47:55 -0300 From: Luiz Capitulino Message-ID: <20110526094755.424cb6c2@doriath> In-Reply-To: References: <1306349281-16913-1-git-send-email-stefanha@linux.vnet.ibm.com> <20110525181522.42eb9a70@doriath> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] QMP: add get_events(wait=True) option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Stefan Hajnoczi , qemu-devel@nongnu.org On Thu, 26 May 2011 09:03:49 +0100 Stefan Hajnoczi wrote: > On Wed, May 25, 2011 at 10:15 PM, Luiz Capitulino > wrote: > > On Wed, 25 May 2011 19:48:00 +0100 > > Stefan Hajnoczi wrote: > > > >> The get_events() function polls for new QMP events and then returns. = =A0It > >> can be useful to wait for the next QMP event so add the boolean 'wait' > >> keyword argument. > >> > >> Signed-off-by: Stefan Hajnoczi > >> --- > >> =A0QMP/qmp.py | =A0 11 ++++++++--- > >> =A01 files changed, 8 insertions(+), 3 deletions(-) > >> > >> diff --git a/QMP/qmp.py b/QMP/qmp.py > >> index 14ce8b0..2565508 100644 > >> --- a/QMP/qmp.py > >> +++ b/QMP/qmp.py > >> @@ -43,7 +43,7 @@ class QEMUMonitorProtocol: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0family =3D socket.AF_UNIX > >> =A0 =A0 =A0 =A0 =A0return socket.socket(family, socket.SOCK_STREAM) > >> > >> - =A0 =A0def __json_read(self): > >> + =A0 =A0def __json_read(self, only_event=3DFalse): > >> =A0 =A0 =A0 =A0 =A0while True: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0data =3D self.__sockfile.readline() > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0if not data: > >> @@ -51,7 +51,8 @@ class QEMUMonitorProtocol: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0resp =3D json.loads(data) > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0if 'event' in resp: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0self.__events.append(resp) > >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if not only_event: > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0return resp > >> > >> =A0 =A0 =A0error =3D socket.error > >> @@ -106,9 +107,11 @@ class QEMUMonitorProtocol: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0qmp_cmd['id'] =3D id > >> =A0 =A0 =A0 =A0 =A0return self.cmd_obj(qmp_cmd) > >> > >> - =A0 =A0def get_events(self): > >> + =A0 =A0def get_events(self, wait=3DFalse): > >> =A0 =A0 =A0 =A0 =A0""" > >> =A0 =A0 =A0 =A0 =A0Get a list of available QMP events. > >> + > >> + =A0 =A0 =A0 =A0@param wait: block until an event is available (bool) > >> =A0 =A0 =A0 =A0 =A0""" > >> =A0 =A0 =A0 =A0 =A0self.__sock.setblocking(0) > >> =A0 =A0 =A0 =A0 =A0try: > >> @@ -118,6 +121,8 @@ class QEMUMonitorProtocol: > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# No data available > >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pass > >> =A0 =A0 =A0 =A0 =A0self.__sock.setblocking(1) > >> + =A0 =A0 =A0 =A0if not self.__events and wait: > >> + =A0 =A0 =A0 =A0 =A0 =A0self.__json_read(only_event=3DTrue) > >> =A0 =A0 =A0 =A0 =A0return self.__events > > > > Maybe this is better (untested): >=20 > I've tested it because that's how I implemented it first too :). > However, I don't want to block until the QMP monitor sends the next > event when there is already a received event pending. >=20 > The patch I posted polls for new events first, then only blocks if > there are no events available. Ok, pushed both patches to the QMP queue. Thanks.