* [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/, lib/portage/util/futures/_asyncio/
@ 2019-05-12 7:05 Zac Medico
0 siblings, 0 replies; only message in thread
From: Zac Medico @ 2019-05-12 7:05 UTC (permalink / raw
To: gentoo-commits
commit: 00340dfa7d85144aa975079d6eeebaa035178208
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun May 12 06:51:49 2019 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun May 12 07:02:03 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=00340dfa
portdbapi._event_loop: split out _safe_loop function
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/dbapi/porttree.py | 10 +---------
lib/portage/util/futures/_asyncio/__init__.py | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
index 7a28f5876..edff0c2f2 100644
--- a/lib/portage/dbapi/porttree.py
+++ b/lib/portage/dbapi/porttree.py
@@ -34,7 +34,6 @@ from portage import eclass_cache, \
from portage import os
from portage import _encodings
from portage import _unicode_encode
-from portage.util._eventloop.EventLoop import EventLoop
from portage.util.futures import asyncio
from portage.util.futures.compat_coroutine import coroutine, coroutine_return
from portage.util.futures.iter_completed import iter_gather
@@ -346,14 +345,7 @@ class portdbapi(dbapi):
@property
def _event_loop(self):
- if portage._internal_caller:
- # For internal portage usage, asyncio._wrap_loop() is safe.
- return asyncio._wrap_loop()
- else:
- # For external API consumers, use a local EventLoop, since
- # we don't want to assume that it's safe to override the
- # global SIGCHLD handler.
- return EventLoop(main=False)
+ return asyncio._safe_loop()
def _create_pregen_cache(self, tree):
conf = self.repositories.get_repo_for_location(tree)
diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py
index 2a637624d..e77c7a690 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -37,6 +37,7 @@ import portage
portage.proxy.lazyimport.lazyimport(globals(),
'portage.util.futures.unix_events:_PortageEventLoopPolicy',
'portage.util.futures:compat_coroutine@_compat_coroutine',
+ 'portage.util._eventloop.EventLoop:EventLoop@_EventLoop',
)
from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop
from portage.util._eventloop.global_event_loop import (
@@ -250,3 +251,20 @@ if _asyncio_enabled:
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 _wrap_loop()
+ else:
+ return _EventLoop(main=False)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-05-12 7:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-12 7:05 [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/, lib/portage/util/futures/_asyncio/ Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox