commit:     631bedffe29124d693de3b539fc908d9feec1420
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Sep 20 05:05:38 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Sep 20 05:08:47 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=631bedff

_safe_loop: fix python3.10 DeprecationWarning

DeprecationWarning: There is no current event loop

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/util/futures/_asyncio/__init__.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/portage/util/futures/_asyncio/__init__.py 
b/lib/portage/util/futures/_asyncio/__init__.py
index c1229528a..ccf800c66 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -280,10 +280,14 @@ def _safe_loop():
             loop = _thread_weakrefs.loops[thread_key]
         except KeyError:
             try:
-                _real_asyncio.get_event_loop()
+                try:
+                    _loop = _real_asyncio.get_running_loop()
+                except AttributeError:
+                    _loop = _real_asyncio.get_event_loop()
             except RuntimeError:
-                _real_asyncio.set_event_loop(_real_asyncio.new_event_loop())
-            loop = _thread_weakrefs.loops[thread_key] = _AsyncioEventLoop()
+                _loop = _real_asyncio.new_event_loop()
+                _real_asyncio.set_event_loop(_loop)
+            loop = _thread_weakrefs.loops[thread_key] = 
_AsyncioEventLoop(loop=_loop)
 
     if (
         _thread_weakrefs.mainloop is None

Reply via email to