[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 08/17] python/qmp: clear events on get_events() call
From: |
John Snow |
Subject: |
[PATCH v2 08/17] python/qmp: clear events on get_events() call |
Date: |
Wed, 22 Sep 2021 20:49:29 -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>
---
python/qemu/machine/machine.py | 1 -
python/qemu/qmp/__init__.py | 6 ++++--
python/qemu/qmp/qmp_shell.py | 1 -
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
index 34131884a57..ae945ca3c94 100644
--- a/python/qemu/machine/machine.py
+++ b/python/qemu/machine/machine.py
@@ -631,7 +631,6 @@ def get_qmp_events(self, wait: bool = False) ->
List[QMPMessage]:
events = self._qmp.get_events(wait=wait)
events.extend(self._events)
del self._events[:]
- self._qmp.clear_events()
return events
@staticmethod
diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py
index 269516a79b9..c27594b66a2 100644
--- a/python/qemu/qmp/__init__.py
+++ b/python/qemu/qmp/__init__.py
@@ -361,7 +361,7 @@ def pull_event(self,
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 @@ def get_events(self, wait: bool = False) ->
List[QMPMessage]:
@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:
"""
diff --git a/python/qemu/qmp/qmp_shell.py b/python/qemu/qmp/qmp_shell.py
index 337acfce2d2..e7d7eb18f19 100644
--- a/python/qemu/qmp/qmp_shell.py
+++ b/python/qemu/qmp/qmp_shell.py
@@ -381,7 +381,6 @@ def read_exec_command(self) -> bool:
if cmdline == '':
for event in self.get_events():
print(event)
- self.clear_events()
return True
return self._execute_cmd(cmdline)
--
2.31.1
- [PATCH v2 00/17] Switch iotests to using Async QMP, John Snow, 2021/09/22
- [PATCH v2 01/17] python/aqmp: add greeting property to QMPClient, John Snow, 2021/09/22
- [PATCH v2 03/17] python/aqmp: Return cleared events from EventListener.clear(), John Snow, 2021/09/22
- [PATCH v2 02/17] python/aqmp: add .empty() method to EventListener, John Snow, 2021/09/22
- [PATCH v2 04/17] python/aqmp: add send_fd_scm, John Snow, 2021/09/22
- [PATCH v2 05/17] python/aqmp: Add dict conversion method to Greeting object, John Snow, 2021/09/22
- [PATCH v2 07/17] python/aqmp: Disable logging messages by default, John Snow, 2021/09/22
- [PATCH v2 06/17] python/aqmp: Reduce severity of EOFError-caused loop terminations, John Snow, 2021/09/22
- [PATCH v2 08/17] python/qmp: clear events on get_events() call,
John Snow <=
- [PATCH v2 09/17] python/qmp: add send_fd_scm directly to QEMUMonitorProtocol, John Snow, 2021/09/22
- [PATCH v2 10/17] python, iotests: remove socket_scm_helper, John Snow, 2021/09/22
- [PATCH v2 11/17] python/machine: remove has_quit argument, John Snow, 2021/09/22
- [PATCH v2 12/17] python/machine: Handle QMP errors on close more meticulously, John Snow, 2021/09/22
- [PATCH v2 15/17] python/aqmp: Create sync QMP wrapper for iotests, John Snow, 2021/09/22
- [PATCH v2 16/17] python/aqmp: Remove scary message, John Snow, 2021/09/22
- [PATCH v2 13/17] iotests: Accommodate async QMP Exception classes, John Snow, 2021/09/22
- [PATCH v2 14/17] iotests: Conditionally silence certain AQMP errors, John Snow, 2021/09/22
- [PATCH v2 17/17] python, iotests: replace qmp with aqmp, John Snow, 2021/09/22