Skip to content

Commit d911acc

Browse files
committed
python/qmp: clear events on get_events() call
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 <[email protected]> Reviewed-by: Hanna Reitz <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Message-id: [email protected] Signed-off-by: John Snow <[email protected]>
1 parent 3a3d84f commit d911acc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

python/qemu/machine/machine.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ def get_qmp_events(self, wait: bool = False) -> List[QMPMessage]:
631631
events = self._qmp.get_events(wait=wait)
632632
events.extend(self._events)
633633
del self._events[:]
634-
self._qmp.clear_events()
635634
return events
636635

637636
@staticmethod

python/qemu/qmp/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def pull_event(self,
361361

362362
def get_events(self, wait: bool = False) -> List[QMPMessage]:
363363
"""
364-
Get a list of available QMP events.
364+
Get a list of available QMP events and clear all pending events.
365365
366366
@param wait (bool): block until an event is available.
367367
@param wait (float): If wait is a float, treat it as a timeout value.
@@ -374,7 +374,9 @@ def get_events(self, wait: bool = False) -> List[QMPMessage]:
374374
@return The list of available QMP events.
375375
"""
376376
self.__get_events(wait)
377-
return self.__events
377+
events = self.__events
378+
self.__events = []
379+
return events
378380

379381
def clear_events(self) -> None:
380382
"""

python/qemu/qmp/qmp_shell.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ def read_exec_command(self) -> bool:
381381
if cmdline == '':
382382
for event in self.get_events():
383383
print(event)
384-
self.clear_events()
385384
return True
386385

387386
return self._execute_cmd(cmdline)

0 commit comments

Comments
 (0)