aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2024-08-31 12:06:25 -0700
committerZac Medico <zmedico@gentoo.org>2024-08-31 12:06:25 -0700
commitee17cbd807ba976491e4c657be8aa9b9a29fe059 (patch)
tree976872ec8d6fd45cada18efe2cb70d3d692c8a32
parentman/emerge.1: Fixed a typo (diff)
downloadportage-ee17cbd807ba976491e4c657be8aa9b9a29fe059.tar.gz
portage-ee17cbd807ba976491e4c657be8aa9b9a29fe059.tar.bz2
portage-ee17cbd807ba976491e4c657be8aa9b9a29fe059.zip
_safe_loop: Discard wrapped asyncio.run loop that was closed
Since commit cb0c09d8cecb, _get_running_loop can wrap loops from asyncio.run, so these loops need to be discarded if they've been closed. Fixes: cb0c09d8cecb ("Support coroutine exitfuncs for non-main loops") Bug: https://bugs.gentoo.org/938761 Bug: https://bugs.gentoo.org/761538 Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/util/futures/_asyncio/__init__.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py
index bdacda59c..23c664e76 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -311,6 +311,13 @@ def _safe_loop(create: Optional[bool] = True) -> Optional[_AsyncioEventLoop]:
_thread_weakrefs.loops = weakref.WeakValueDictionary()
try:
loop = _thread_weakrefs.loops[thread_key]
+ if loop.is_closed():
+ # Discard wrapped asyncio.run loop that was closed.
+ del _thread_weakrefs.loops[thread_key]
+ if loop is _thread_weakrefs.mainloop:
+ _thread_weakrefs.mainloop = None
+ loop = None
+ raise KeyError(thread_key)
except KeyError:
if not create:
return None