Revision 91b8eddf

b/QMP/qmp.py
43 43
            family = socket.AF_UNIX
44 44
        return socket.socket(family, socket.SOCK_STREAM)
45 45

  
46
    def __json_read(self):
46
    def __json_read(self, only_event=False):
47 47
        while True:
48 48
            data = self.__sockfile.readline()
49 49
            if not data:
......
51 51
            resp = json.loads(data)
52 52
            if 'event' in resp:
53 53
                self.__events.append(resp)
54
                continue
54
                if not only_event:
55
                    continue
55 56
            return resp
56 57

  
57 58
    error = socket.error
......
106 107
            qmp_cmd['id'] = id
107 108
        return self.cmd_obj(qmp_cmd)
108 109

  
109
    def get_events(self):
110
    def get_events(self, wait=False):
110 111
        """
111 112
        Get a list of available QMP events.
113

  
114
        @param wait: block until an event is available (bool)
112 115
        """
113 116
        self.__sock.setblocking(0)
114 117
        try:
......
118 121
                # No data available
119 122
                pass
120 123
        self.__sock.setblocking(1)
124
        if not self.__events and wait:
125
            self.__json_read(only_event=True)
121 126
        return self.__events
122 127

  
123 128
    def clear_events(self):

Also available in: Unified diff