Make the _safe_loop function an alias for the global_event_loop
function, so that the default asyncio event loop implementation
will be used in API consumer threads. This is possible because
global_event_loop has been fixed (bug 758740) to always use
AsyncioEventLoop, and that uses asyncio.get_event_loop() which
returns a new event loop for each thread.

Bug: https://bugs.gentoo.org/758755
Signed-off-by: Zac Medico <zmed...@gentoo.org>
---
 lib/portage/util/futures/_asyncio/__init__.py | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/lib/portage/util/futures/_asyncio/__init__.py 
b/lib/portage/util/futures/_asyncio/__init__.py
index a902ad895..ce3685709 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -39,6 +39,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
 from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as 
_AsyncioEventLoop
 from portage.util._eventloop.global_event_loop import (
        global_event_loop as _global_event_loop,
+       global_event_loop as _safe_loop,
 )
 # pylint: disable=redefined-builtin
 from portage.util.futures.futures import (
@@ -241,19 +242,3 @@ def _wrap_loop(loop=None):
        loop = loop or _global_event_loop()
        return (loop if hasattr(loop, '_asyncio_wrapper')
                else _AsyncioEventLoop(loop=loop))
-
-
-def _safe_loop():
-       """
-       Return an event loop that's safe to use within the current context.
-       For portage internal callers, this returns a globally shared event
-       loop instance. For external API consumers, this constructs a
-       temporary event loop instance that's safe to use in a non-main
-       thread (it does not override the global SIGCHLD handler).
-
-       @rtype: asyncio.AbstractEventLoop (or compatible)
-       @return: event loop instance
-       """
-       if portage._internal_caller:
-               return _global_event_loop()
-       return _EventLoop(main=False)
-- 
2.26.2


Reply via email to