]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
python/qmp: clear events on get_events() call
authorJohn Snow <jsnow@redhat.com>
Thu, 23 Sep 2021 00:49:29 +0000 (20:49 -0400)
committerJohn Snow <jsnow@redhat.com>
Tue, 12 Oct 2021 16:22:11 +0000 (12:22 -0400)
All callers in the tree *already* clear the events after a call to
get_events(). Do it automatically instead and update callsites to remove
the manual clear call.

These semantics are quite a bit easier to emulate with async QMP, and
nobody appears to be abusing some emergent properties of what happens if
you decide not to clear them, so let's dial down to the dumber, simpler
thing.

Specifically: callers of clear() right after a call to get_events() are
more likely expressing their desire to not see any events they just
retrieved, whereas callers of clear_events() not in relation to a recent
call to pull_event/get_events are likely expressing their desire to
simply drop *all* pending events straight onto the floor. In the sync
world, this is safe enough; in the async world it's nearly impossible to
promise that nothing happens between getting and clearing the
events.

Making the retrieval also clear the queue is vastly simpler.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20210923004938.3999963-9-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
python/qemu/machine/machine.py
python/qemu/qmp/__init__.py
python/qemu/qmp/qmp_shell.py

index 34131884a57ca45363beb222ad3e5f3a51e80fc6..ae945ca3c945f02af390902543a2a3eae234871b 100644 (file)
@@ -631,7 +631,6 @@ class QEMUMachine:
         events = self._qmp.get_events(wait=wait)
         events.extend(self._events)
         del self._events[:]
-        self._qmp.clear_events()
         return events
 
     @staticmethod
index 269516a79b90aa6ced483a192de5927a803ed942..c27594b66a2d70afbd7fe62545cb863fd2dbfe50 100644 (file)
@@ -361,7 +361,7 @@ class QEMUMonitorProtocol:
 
     def get_events(self, wait: bool = False) -> List[QMPMessage]:
         """
-        Get a list of available QMP events.
+        Get a list of available QMP events and clear all pending events.
 
         @param wait (bool): block until an event is available.
         @param wait (float): If wait is a float, treat it as a timeout value.
@@ -374,7 +374,9 @@ class QEMUMonitorProtocol:
         @return The list of available QMP events.
         """
         self.__get_events(wait)
-        return self.__events
+        events = self.__events
+        self.__events = []
+        return events
 
     def clear_events(self) -> None:
         """
index 337acfce2d26715359fa190603c5fc6708ccffd5..e7d7eb18f19cae7ac185b333013e914a02967a99 100644 (file)
@@ -381,7 +381,6 @@ class QMPShell(qmp.QEMUMonitorProtocol):
         if cmdline == '':
             for event in self.get_events():
                 print(event)
-            self.clear_events()
             return True
 
         return self._execute_cmd(cmdline)