From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Cleber Rosa" <crosa@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Michael Roth" <michael.roth@amd.com>,
"Markus Armbruster" <armbru@redhat.com>,
"John Snow" <jsnow@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [PULL 2/2] python: avoid deprecation warning with get_event_loop
Date: Wed, 20 Aug 2025 00:58:16 -0400 [thread overview]
Message-ID: <20250820045816.1142190-3-jsnow@redhat.com> (raw)
In-Reply-To: <20250820045816.1142190-1-jsnow@redhat.com>
From: Daniel P. Berrangé <berrange@redhat.com>
We need to call get_event_loop but have no way of knowing ahead
of time whether the current thread has an event loop of not. We
can handle a missing event loop, but we need to hide the warning
python will emit to avoid tripping up iotests expected output.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/qmp/legacy.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/python/qemu/qmp/legacy.py b/python/qemu/qmp/legacy.py
index e11d05afbd6..c6ab3edc867 100644
--- a/python/qemu/qmp/legacy.py
+++ b/python/qemu/qmp/legacy.py
@@ -34,6 +34,7 @@
TypeVar,
Union,
)
+import warnings
from .error import QMPError
from .protocol import Runstate, SocketAddrT
@@ -87,7 +88,11 @@ def __init__(self,
self._qmp = QMPClient(nickname)
try:
- self._aloop = asyncio.get_event_loop()
+ with warnings.catch_warnings():
+ # Python <= 3.13 will trigger deprecation warnings
+ # if no event loop is set
+ warnings.simplefilter("ignore")
+ self._aloop = asyncio.get_event_loop()
except RuntimeError:
self._aloop = asyncio.new_event_loop()
self._address = address
--
2.50.1
next prev parent reply other threads:[~2025-08-20 4:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 4:58 [PULL 0/2] Python patches John Snow
2025-08-20 4:58 ` [PULL 1/2] python: Replace asyncio.get_event_loop for Python 3.14 John Snow
2025-08-20 4:58 ` John Snow [this message]
2025-08-20 5:01 ` [PULL 0/2] Python patches John Snow
2025-08-20 13:33 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250820045816.1142190-3-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=crosa@redhat.com \
--cc=eblake@redhat.com \
--cc=michael.roth@amd.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).