diff options
author | Zac Medico <zmedico@gentoo.org> | 2018-05-09 00:33:37 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2018-05-09 00:40:34 -0700 |
commit | 5e628787e6f4c720680aeeb8beeac88e37988a9e (patch) | |
tree | 2c1faa15d1b5a09c35376e9b64f4c6f48cec0a26 | |
parent | _wrap_loop: default to global_event_loop behavior (diff) | |
download | portage-5e628787.tar.gz portage-5e628787.tar.bz2 portage-5e628787.zip |
DefaultEventLoopPolicy: raise NotImplementedError, not RecursionError
Since the DefaultEventLoopPolicy wraps the underlying asyncio event
loop policy, raise NotImplementedError if the current instance is set
as the underlying event loop policy. This avoids a RecursionError
that would flood the terminal with a large stack trace.
-rw-r--r-- | pym/portage/util/futures/_asyncio/__init__.py | 6 | ||||
-rw-r--r-- | pym/portage/util/futures/unix_events.py | 23 |
2 files changed, 25 insertions, 4 deletions
diff --git a/pym/portage/util/futures/_asyncio/__init__.py b/pym/portage/util/futures/_asyncio/__init__.py index 940da4762..acfd59396 100644 --- a/pym/portage/util/futures/_asyncio/__init__.py +++ b/pym/portage/util/futures/_asyncio/__init__.py @@ -32,7 +32,7 @@ except ImportError: import portage portage.proxy.lazyimport.lazyimport(globals(), - 'portage.util.futures.unix_events:DefaultEventLoopPolicy', + 'portage.util.futures.unix_events:_PortageEventLoopPolicy', ) from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop from portage.util._eventloop.global_event_loop import ( @@ -67,7 +67,7 @@ def get_event_loop_policy(): global _lock, _policy with _lock: if _policy is None: - _policy = DefaultEventLoopPolicy() + _policy = _PortageEventLoopPolicy() return _policy @@ -81,7 +81,7 @@ def set_event_loop_policy(policy): """ global _lock, _policy with _lock: - _policy = policy or DefaultEventLoopPolicy() + _policy = policy or _PortageEventLoopPolicy() def get_event_loop(): diff --git a/pym/portage/util/futures/unix_events.py b/pym/portage/util/futures/unix_events.py index 8eb369f8b..3381eaa7d 100644 --- a/pym/portage/util/futures/unix_events.py +++ b/pym/portage/util/futures/unix_events.py @@ -681,4 +681,25 @@ class _PortageEventLoopPolicy(events.AbstractEventLoopPolicy): return _global_event_loop()._asyncio_child_watcher -DefaultEventLoopPolicy = _PortageEventLoopPolicy +class _AsyncioEventLoopPolicy(_PortageEventLoopPolicy): + """ + A subclass of _PortageEventLoopPolicy which raises + NotImplementedError if it is set as the real asyncio event loop + policy, since this class is intended to *wrap* the real asyncio + event loop policy. + """ + def _check_recursion(self): + if _real_asyncio.get_event_loop_policy() is self: + raise NotImplementedError('this class is only a wrapper') + + def get_event_loop(self): + self._check_recursion() + return super(_AsyncioEventLoopPolicy, self).get_event_loop() + + def get_child_watcher(self): + self._check_recursion() + return super(_AsyncioEventLoopPolicy, self).get_child_watcher() + + +DefaultEventLoopPolicy = (_AsyncioEventLoopPolicy if _asyncio_enabled + else _PortageEventLoopPolicy) |