Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/futures/_asyncio/, pym/portage/util/futures/
Date: Wed, 09 May 2018 07:43:49
Message-Id: 1525851634.5e628787e6f4c720680aeeb8beeac88e37988a9e.zmedico@gentoo
1 commit: 5e628787e6f4c720680aeeb8beeac88e37988a9e
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Wed May 9 07:33:37 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed May 9 07:40:34 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=5e628787
7
8 DefaultEventLoopPolicy: raise NotImplementedError, not RecursionError
9
10 Since the DefaultEventLoopPolicy wraps the underlying asyncio event
11 loop policy, raise NotImplementedError if the current instance is set
12 as the underlying event loop policy. This avoids a RecursionError
13 that would flood the terminal with a large stack trace.
14
15 pym/portage/util/futures/_asyncio/__init__.py | 6 +++---
16 pym/portage/util/futures/unix_events.py | 23 ++++++++++++++++++++++-
17 2 files changed, 25 insertions(+), 4 deletions(-)
18
19 diff --git a/pym/portage/util/futures/_asyncio/__init__.py b/pym/portage/util/futures/_asyncio/__init__.py
20 index 940da4762..acfd59396 100644
21 --- a/pym/portage/util/futures/_asyncio/__init__.py
22 +++ b/pym/portage/util/futures/_asyncio/__init__.py
23 @@ -32,7 +32,7 @@ except ImportError:
24
25 import portage
26 portage.proxy.lazyimport.lazyimport(globals(),
27 - 'portage.util.futures.unix_events:DefaultEventLoopPolicy',
28 + 'portage.util.futures.unix_events:_PortageEventLoopPolicy',
29 )
30 from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop
31 from portage.util._eventloop.global_event_loop import (
32 @@ -67,7 +67,7 @@ def get_event_loop_policy():
33 global _lock, _policy
34 with _lock:
35 if _policy is None:
36 - _policy = DefaultEventLoopPolicy()
37 + _policy = _PortageEventLoopPolicy()
38 return _policy
39
40
41 @@ -81,7 +81,7 @@ def set_event_loop_policy(policy):
42 """
43 global _lock, _policy
44 with _lock:
45 - _policy = policy or DefaultEventLoopPolicy()
46 + _policy = policy or _PortageEventLoopPolicy()
47
48
49 def get_event_loop():
50
51 diff --git a/pym/portage/util/futures/unix_events.py b/pym/portage/util/futures/unix_events.py
52 index 8eb369f8b..3381eaa7d 100644
53 --- a/pym/portage/util/futures/unix_events.py
54 +++ b/pym/portage/util/futures/unix_events.py
55 @@ -681,4 +681,25 @@ class _PortageEventLoopPolicy(events.AbstractEventLoopPolicy):
56 return _global_event_loop()._asyncio_child_watcher
57
58
59 -DefaultEventLoopPolicy = _PortageEventLoopPolicy
60 +class _AsyncioEventLoopPolicy(_PortageEventLoopPolicy):
61 + """
62 + A subclass of _PortageEventLoopPolicy which raises
63 + NotImplementedError if it is set as the real asyncio event loop
64 + policy, since this class is intended to *wrap* the real asyncio
65 + event loop policy.
66 + """
67 + def _check_recursion(self):
68 + if _real_asyncio.get_event_loop_policy() is self:
69 + raise NotImplementedError('this class is only a wrapper')
70 +
71 + def get_event_loop(self):
72 + self._check_recursion()
73 + return super(_AsyncioEventLoopPolicy, self).get_event_loop()
74 +
75 + def get_child_watcher(self):
76 + self._check_recursion()
77 + return super(_AsyncioEventLoopPolicy, self).get_child_watcher()
78 +
79 +
80 +DefaultEventLoopPolicy = (_AsyncioEventLoopPolicy if _asyncio_enabled
81 + else _PortageEventLoopPolicy)