[PATCH 02/14] python: avoid deprecation warning with get_event_loop

Daniel P. Berrangé posted 14 patches 4 months ago
Maintainers: John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Elena Ufimtseva <elena.ufimtseva@oracle.com>, Jagannathan Raman <jag.raman@oracle.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
[PATCH 02/14] python: avoid deprecation warning with get_event_loop
Posted by Daniel P. Berrangé 4 months ago
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>
---
 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 e11d05afbd..c6ab3edc86 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.49.0


Re: [PATCH 02/14] python: avoid deprecation warning with get_event_loop
Posted by Eric Blake 3 months, 3 weeks ago
On Tue, Jul 15, 2025 at 03:30:11PM +0100, Daniel P. Berrangé wrote:
> 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

s/of not /or not /

> 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>
> ---
>  python/qemu/qmp/legacy.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Re: [PATCH 02/14] python: avoid deprecation warning with get_event_loop
Posted by John Snow 2 months, 3 weeks ago
On Wed, Jul 23, 2025 at 5:25 PM Eric Blake <eblake@redhat.com> wrote:
>
> On Tue, Jul 15, 2025 at 03:30:11PM +0100, Daniel P. Berrangé wrote:
> > 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
>
> s/of not /or not /
>
> > 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: John Snow <jsnow@redhat.com>

Do you mind if I collect this patch and apply it against the standalone tree?

--js

> > ---
> >  python/qemu/qmp/legacy.py | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.
> Virtualization:  qemu.org | libguestfs.org
>
Re: [PATCH 02/14] python: avoid deprecation warning with get_event_loop
Posted by Daniel P. Berrangé 2 months, 3 weeks ago
On Tue, Aug 19, 2025 at 03:49:30PM -0400, John Snow wrote:
> On Wed, Jul 23, 2025 at 5:25 PM Eric Blake <eblake@redhat.com> wrote:
> >
> > On Tue, Jul 15, 2025 at 03:30:11PM +0100, Daniel P. Berrangé wrote:
> > > 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
> >
> > s/of not /or not /
> >
> > > 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: John Snow <jsnow@redhat.com>
> 
> Do you mind if I collect this patch and apply it against the standalone tree?

If it applies cleanly, then go ahead, and likewise for anything
else following in this series.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|