From: "Daniel P. Berrange" <[email protected]> The qmp-shell code assumes the JSON response is only on a single line. If the QEMU monitor is configured in "pretty print" mode the JSON response can be multi-line. The basic Python JSON APIs do not appear to support a streaming mode, so the simple hack here is to try parsing a line, and if it fails, then read another line, append it, and try parsing again. Keep reading lines until we can successfully parse
Signed-off-by: Daniel P. Berrange <[email protected]> --- QMP/qmp.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/QMP/qmp.py b/QMP/qmp.py index 36ecc1d..464a01a 100644 --- a/QMP/qmp.py +++ b/QMP/qmp.py @@ -61,10 +61,18 @@ class QEMUMonitorProtocol: def __json_read(self, only_event=False): while True: - data = self.__sockfile.readline() - if not data: - return - resp = json.loads(data) + data = "" + while True: + moredata = self.__sockfile.readline() + if not moredata: + return + data = data + moredata + try: + resp = json.loads(data) + break + except ValueError: + pass + if 'event' in resp: self.__events.append(resp) if not only_event: -- 1.7.11.2
