diff mbox series

[2/3] python/qemu/qmp.py: re-raise OSError when encountered

Message ID 20201009175123.249009-3-jsnow@redhat.com
State New
Headers show
Series python/qemu: strictly typed mypy conversion, pt3 | expand

Commit Message

John Snow Oct. 9, 2020, 5:51 p.m. UTC
Nested if conditions don't change when the exception block fires; we
need to explicitly re-raise the error if we didn't intend to capture and
suppress it.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 python/qemu/qmp.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Philippe Mathieu-Daudé Oct. 9, 2020, 7:34 p.m. UTC | #1
On 10/9/20 7:51 PM, John Snow wrote:
> Nested if conditions don't change when the exception block fires; we

> need to explicitly re-raise the error if we didn't intend to capture and

> suppress it.

> 

> Signed-off-by: John Snow <jsnow@redhat.com>

> ---

>   python/qemu/qmp.py | 11 ++++++-----

>   1 file changed, 6 insertions(+), 5 deletions(-)


Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py
index d911999da1f..4969e5741cb 100644
--- a/python/qemu/qmp.py
+++ b/python/qemu/qmp.py
@@ -165,14 +165,15 @@  def __get_events(self, wait: Union[bool, float] = False) -> None:
         """
 
         # Check for new events regardless and pull them into the cache:
-        self.__sock.setblocking(False)
         try:
+            self.__sock.setblocking(False)
             self.__json_read()
         except OSError as err:
-            if err.errno == errno.EAGAIN:
-                # No data available
-                pass
-        self.__sock.setblocking(True)
+            # EAGAIN: No data available; not critical
+            if err.errno != errno.EAGAIN:
+                raise
+        finally:
+            self.__sock.setblocking(True)
 
         # Wait for new events, if needed.
         # if wait is 0.0, this means "no wait" and is also implicitly false.