Received: from eggs.gnu.org ([208.118.235.92]:56951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Stcwe-0008Gb-Uk for qemu-devel@nongnu.org; Tue, 24 Jul 2012 07:06:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StcwV-0005rw-Dd for qemu-devel@nongnu.org; Tue, 24 Jul 2012 07:06:28 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:36778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StcwV-00058R-96 for qemu-devel@nongnu.org; Tue, 24 Jul 2012 07:06:19 -0400 Received: by mail-yw0-f45.google.com with SMTP id p34so6575216yhp.4 for ; Tue, 24 Jul 2012 04:06:19 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 24 Jul 2012 13:04:12 +0200 Message-Id: <1343127865-16608-35-git-send-email-pbonzini@redhat.com> In-Reply-To: <1343127865-16608-1-git-send-email-pbonzini@redhat.com> References: <1343127865-16608-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 34/47] qmp: add pull_event function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com, eblake@redhat.com, stefanha@linux.vnet.ibm.com, Luiz Capitulino This function is unlike get_events, in that it makes it easy to process one event at a time. This is useful in the mirroring test cases, where we want to process just one event (BLOCK_JOB_ERROR) and leave the others to a helper function. Cc: Luiz Capitulino Signed-off-by: Paolo Bonzini --- QMP/qmp.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/QMP/qmp.py b/QMP/qmp.py index bd83a21..db1b76a 100644 --- a/QMP/qmp.py +++ b/QMP/qmp.py @@ -136,6 +136,26 @@ class QEMUMonitorProtocol: raise Exception(ret['error']['desc']) return ret['return'] + def pull_event(self, wait=False): + """ + Get and delete the first available QMP event. + + @param wait: block until an event is available (bool) + """ + self.__sock.setblocking(0) + try: + self.__json_read() + except socket.error, err: + if err[0] == errno.EAGAIN: + # No data available + pass + self.__sock.setblocking(1) + if not self.__events and wait: + self.__json_read(only_event=True) + event = self.__events[0] + del self.__events[0] + return event + def get_events(self, wait=False): """ Get a list of available QMP events. -- 1.7.10.4