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 05:01:49
Message-Id: 1525841999.920b90fd0883dbd36f0290d08c9af49a208c2950.zmedico@gentoo
1 commit: 920b90fd0883dbd36f0290d08c9af49a208c2950
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Wed May 9 04:59:59 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Wed May 9 04:59:59 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=920b90fd
7
8 _wrap_loop: default to global_event_loop behavior
9
10 The default loop returned by _wrap_loop should be consistent
11 with global_event_loop, in order to avoid accidental registration
12 of callbacks with a loop that is not intended to run.
13
14 Fixes 96cc07326391 ("global_event_loop: use asyncio event loop (bug 654390)")
15
16 pym/portage/util/futures/_asyncio/__init__.py | 14 ++++++----
17 pym/portage/util/futures/unix_events.py | 40 +--------------------------
18 2 files changed, 10 insertions(+), 44 deletions(-)
19
20 diff --git a/pym/portage/util/futures/_asyncio/__init__.py b/pym/portage/util/futures/_asyncio/__init__.py
21 index 1273afa02..940da4762 100644
22 --- a/pym/portage/util/futures/_asyncio/__init__.py
23 +++ b/pym/portage/util/futures/_asyncio/__init__.py
24 @@ -35,7 +35,10 @@ portage.proxy.lazyimport.lazyimport(globals(),
25 'portage.util.futures.unix_events:DefaultEventLoopPolicy',
26 )
27 from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop
28 -from portage.util._eventloop.global_event_loop import _asyncio_enabled
29 +from portage.util._eventloop.global_event_loop import (
30 + _asyncio_enabled,
31 + global_event_loop as _global_event_loop,
32 +)
33 from portage.util.futures.futures import (
34 CancelledError,
35 Future,
36 @@ -168,14 +171,15 @@ def _wrap_loop(loop=None):
37 @rtype: asyncio.AbstractEventLoop (or compatible)
38 @return: event loop
39 """
40 - return loop or get_event_loop()
41 + return loop or _global_event_loop()
42
43
44 if _asyncio_enabled:
45 - get_event_loop_policy = _real_asyncio.get_event_loop_policy
46 - set_event_loop_policy = _real_asyncio.set_event_loop_policy
47 + # The default loop returned by _wrap_loop should be consistent
48 + # with global_event_loop, in order to avoid accidental registration
49 + # of callbacks with a loop that is not intended to run.
50
51 def _wrap_loop(loop=None):
52 - loop = loop or get_event_loop()
53 + loop = loop or _global_event_loop()
54 return (loop if hasattr(loop, '_asyncio_wrapper')
55 else _AsyncioEventLoop(loop=loop))
56
57 diff --git a/pym/portage/util/futures/unix_events.py b/pym/portage/util/futures/unix_events.py
58 index ce520db00..8eb369f8b 100644
59 --- a/pym/portage/util/futures/unix_events.py
60 +++ b/pym/portage/util/futures/unix_events.py
61 @@ -681,42 +681,4 @@ class _PortageEventLoopPolicy(events.AbstractEventLoopPolicy):
62 return _global_event_loop()._asyncio_child_watcher
63
64
65 -class _AsyncioEventLoopPolicy(_PortageEventLoopPolicy):
66 - """
67 - Implementation of asyncio.AbstractEventLoopPolicy based on asyncio's
68 - event loop. This supports running event loops in forks,
69 - which is not supported by the default asyncio event loop policy,
70 - see https://bugs.python.org/issue22087 and also
71 - https://bugs.python.org/issue29703 which affects pypy3-5.10.1.
72 - """
73 - _MAIN_PID = os.getpid()
74 -
75 - def __init__(self):
76 - super(_AsyncioEventLoopPolicy, self).__init__()
77 - self._default_policy = _real_asyncio.DefaultEventLoopPolicy()
78 -
79 - def get_event_loop(self):
80 - """
81 - Get the event loop for the current context.
82 -
83 - Returns an event loop object implementing the AbstractEventLoop
84 - interface.
85 -
86 - @rtype: asyncio.AbstractEventLoop (or compatible)
87 - @return: the current event loop policy
88 - """
89 - if os.getpid() == self._MAIN_PID:
90 - return self._default_policy.get_event_loop()
91 - else:
92 - return super(_AsyncioEventLoopPolicy, self).get_event_loop()
93 -
94 - def get_child_watcher(self):
95 - """Get the watcher for child processes."""
96 - if os.getpid() == self._MAIN_PID:
97 - return self._default_policy.get_child_watcher()
98 - else:
99 - return super(_AsyncioEventLoopPolicy, self).get_child_watcher()
100 -
101 -
102 -DefaultEventLoopPolicy = (_AsyncioEventLoopPolicy if _asyncio_enabled
103 - else _PortageEventLoopPolicy)
104 +DefaultEventLoopPolicy = _PortageEventLoopPolicy