1 |
commit: 82a3cda6f1ffbbbd75c962d610c7eb4a04a865d9 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 5 21:00:51 2018 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 5 21:00:51 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=82a3cda6 |
7 |
|
8 |
Minimize _asyncio_wrapper usage (bug 654390) |
9 |
|
10 |
Since migration to asyncio compatible APIs is now complete, |
11 |
minimize _asyncio_wrapper usage. Also remove _asyncio_wrapper from |
12 |
SchedulerInterface, since there are no more consumers. |
13 |
|
14 |
Bug: https://bugs.gentoo.org/654390 |
15 |
|
16 |
pym/_emerge/AbstractPollTask.py | 2 +- |
17 |
pym/portage/_emirrordist/FetchIterator.py | 1 - |
18 |
pym/portage/dbapi/porttree.py | 3 --- |
19 |
.../tests/util/futures/asyncio/test_subprocess_exec.py | 1 - |
20 |
pym/portage/tests/util/futures/test_iter_completed.py | 4 ++-- |
21 |
pym/portage/tests/util/futures/test_retry.py | 16 ++++++++-------- |
22 |
pym/portage/util/_async/SchedulerInterface.py | 1 - |
23 |
pym/portage/util/futures/__init__.py | 5 +---- |
24 |
pym/portage/util/futures/_asyncio/tasks.py | 1 - |
25 |
pym/portage/util/futures/executor/fork.py | 3 +-- |
26 |
pym/portage/util/futures/futures.py | 2 +- |
27 |
pym/portage/util/futures/iter_completed.py | 3 --- |
28 |
12 files changed, 14 insertions(+), 28 deletions(-) |
29 |
|
30 |
diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py |
31 |
index dff4b3efd..f898aa708 100644 |
32 |
--- a/pym/_emerge/AbstractPollTask.py |
33 |
+++ b/pym/_emerge/AbstractPollTask.py |
34 |
@@ -109,7 +109,7 @@ class AbstractPollTask(AsynchronousTask): |
35 |
self._registered = False |
36 |
|
37 |
def _wait_loop(self, timeout=None): |
38 |
- loop = getattr(self.scheduler, '_asyncio_wrapper', self.scheduler) |
39 |
+ loop = self.scheduler |
40 |
tasks = [self.async_wait()] |
41 |
if timeout is not None: |
42 |
tasks.append(asyncio.ensure_future( |
43 |
|
44 |
diff --git a/pym/portage/_emirrordist/FetchIterator.py b/pym/portage/_emirrordist/FetchIterator.py |
45 |
index 366453c12..04d4da62b 100644 |
46 |
--- a/pym/portage/_emirrordist/FetchIterator.py |
47 |
+++ b/pym/portage/_emirrordist/FetchIterator.py |
48 |
@@ -125,7 +125,6 @@ def _async_fetch_tasks(config, hash_filter, repo_config, digests_future, cpv, |
49 |
instances for each of the files referenced by an ebuild. |
50 |
@rtype: asyncio.Future (or compatible) |
51 |
""" |
52 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
53 |
result = loop.create_future() |
54 |
fetch_tasks = [] |
55 |
|
56 |
|
57 |
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py |
58 |
index 6c38232bb..801b5658a 100644 |
59 |
--- a/pym/portage/dbapi/porttree.py |
60 |
+++ b/pym/portage/dbapi/porttree.py |
61 |
@@ -612,7 +612,6 @@ class portdbapi(dbapi): |
62 |
# Callers of this method certainly want the same event loop to |
63 |
# be used for all calls. |
64 |
loop = loop or global_event_loop() |
65 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
66 |
future = loop.create_future() |
67 |
cache_me = False |
68 |
if myrepo is not None: |
69 |
@@ -753,7 +752,6 @@ class portdbapi(dbapi): |
70 |
@rtype: asyncio.Future (or compatible) |
71 |
""" |
72 |
loop = loop or global_event_loop() |
73 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
74 |
result = loop.create_future() |
75 |
|
76 |
def aux_get_done(aux_get_future): |
77 |
@@ -1422,7 +1420,6 @@ def _async_manifest_fetchlist(portdb, repo_config, cp, cpv_list=None, |
78 |
@rtype: asyncio.Future (or compatible) |
79 |
""" |
80 |
loop = loop or global_event_loop() |
81 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
82 |
result = loop.create_future() |
83 |
cpv_list = (portdb.cp_list(cp, mytree=repo_config.location) |
84 |
if cpv_list is None else cpv_list) |
85 |
|
86 |
diff --git a/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py b/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py |
87 |
index be103a9e0..98983941d 100644 |
88 |
--- a/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py |
89 |
+++ b/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py |
90 |
@@ -24,7 +24,6 @@ def reader(input_file, loop=None): |
91 |
@rtype: asyncio.Future (or compatible) |
92 |
""" |
93 |
loop = loop or asyncio.get_event_loop() |
94 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
95 |
future = loop.create_future() |
96 |
_Reader(future, input_file, loop) |
97 |
return future |
98 |
|
99 |
diff --git a/pym/portage/tests/util/futures/test_iter_completed.py b/pym/portage/tests/util/futures/test_iter_completed.py |
100 |
index 90668eb02..9ab410a9e 100644 |
101 |
--- a/pym/portage/tests/util/futures/test_iter_completed.py |
102 |
+++ b/pym/portage/tests/util/futures/test_iter_completed.py |
103 |
@@ -34,7 +34,7 @@ class IterCompletedTestCase(TestCase): |
104 |
# load causes the tasks to finish in an unexpected order. |
105 |
self.todo = True |
106 |
|
107 |
- loop = global_event_loop()._asyncio_wrapper |
108 |
+ loop = global_event_loop() |
109 |
tasks = [ |
110 |
SleepProcess(seconds=0.200), |
111 |
SleepProcess(seconds=0.100), |
112 |
@@ -56,7 +56,7 @@ class IterCompletedTestCase(TestCase): |
113 |
|
114 |
def testAsyncCancel(self): |
115 |
|
116 |
- loop = global_event_loop()._asyncio_wrapper |
117 |
+ loop = global_event_loop() |
118 |
input_futures = set() |
119 |
future_count = 3 |
120 |
|
121 |
|
122 |
diff --git a/pym/portage/tests/util/futures/test_retry.py b/pym/portage/tests/util/futures/test_retry.py |
123 |
index 27d8c7b61..cdca7d294 100644 |
124 |
--- a/pym/portage/tests/util/futures/test_retry.py |
125 |
+++ b/pym/portage/tests/util/futures/test_retry.py |
126 |
@@ -56,7 +56,7 @@ class HangForever(object): |
127 |
|
128 |
class RetryTestCase(TestCase): |
129 |
def testSucceedLater(self): |
130 |
- loop = global_event_loop()._asyncio_wrapper |
131 |
+ loop = global_event_loop() |
132 |
func = SucceedLater(1) |
133 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
134 |
decorator = retry(try_max=9999, |
135 |
@@ -66,7 +66,7 @@ class RetryTestCase(TestCase): |
136 |
self.assertEqual(result, 'success') |
137 |
|
138 |
def testSucceedNever(self): |
139 |
- loop = global_event_loop()._asyncio_wrapper |
140 |
+ loop = global_event_loop() |
141 |
func = SucceedNever() |
142 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
143 |
decorator = retry(try_max=4, try_timeout=None, |
144 |
@@ -77,7 +77,7 @@ class RetryTestCase(TestCase): |
145 |
self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) |
146 |
|
147 |
def testSucceedNeverReraise(self): |
148 |
- loop = global_event_loop()._asyncio_wrapper |
149 |
+ loop = global_event_loop() |
150 |
func = SucceedNever() |
151 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
152 |
decorator = retry(reraise=True, try_max=4, try_timeout=None, |
153 |
@@ -88,7 +88,7 @@ class RetryTestCase(TestCase): |
154 |
self.assertTrue(isinstance(done.pop().exception(), SucceedNeverException)) |
155 |
|
156 |
def testHangForever(self): |
157 |
- loop = global_event_loop()._asyncio_wrapper |
158 |
+ loop = global_event_loop() |
159 |
func = HangForever() |
160 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
161 |
decorator = retry(try_max=2, try_timeout=0.1, |
162 |
@@ -99,7 +99,7 @@ class RetryTestCase(TestCase): |
163 |
self.assertTrue(isinstance(done.pop().exception().__cause__, asyncio.TimeoutError)) |
164 |
|
165 |
def testHangForeverReraise(self): |
166 |
- loop = global_event_loop()._asyncio_wrapper |
167 |
+ loop = global_event_loop() |
168 |
func = HangForever() |
169 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
170 |
decorator = retry(reraise=True, try_max=2, try_timeout=0.1, |
171 |
@@ -110,7 +110,7 @@ class RetryTestCase(TestCase): |
172 |
self.assertTrue(isinstance(done.pop().exception(), asyncio.TimeoutError)) |
173 |
|
174 |
def testCancelRetry(self): |
175 |
- loop = global_event_loop()._asyncio_wrapper |
176 |
+ loop = global_event_loop() |
177 |
func = SucceedNever() |
178 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
179 |
decorator = retry(try_timeout=0.1, |
180 |
@@ -123,7 +123,7 @@ class RetryTestCase(TestCase): |
181 |
self.assertTrue(done.pop().cancelled()) |
182 |
|
183 |
def testOverallTimeoutWithException(self): |
184 |
- loop = global_event_loop()._asyncio_wrapper |
185 |
+ loop = global_event_loop() |
186 |
func = SucceedNever() |
187 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
188 |
decorator = retry(try_timeout=0.1, overall_timeout=0.3, |
189 |
@@ -134,7 +134,7 @@ class RetryTestCase(TestCase): |
190 |
self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) |
191 |
|
192 |
def testOverallTimeoutWithTimeoutError(self): |
193 |
- loop = global_event_loop()._asyncio_wrapper |
194 |
+ loop = global_event_loop() |
195 |
# results in TimeoutError because it hangs forever |
196 |
func = HangForever() |
197 |
func_coroutine = functools.partial(loop.run_in_executor, None, func) |
198 |
|
199 |
diff --git a/pym/portage/util/_async/SchedulerInterface.py b/pym/portage/util/_async/SchedulerInterface.py |
200 |
index 718fbc8e7..f1a3e9b0b 100644 |
201 |
--- a/pym/portage/util/_async/SchedulerInterface.py |
202 |
+++ b/pym/portage/util/_async/SchedulerInterface.py |
203 |
@@ -33,7 +33,6 @@ class SchedulerInterface(SlotObject): |
204 |
"time", |
205 |
|
206 |
"_asyncio_child_watcher", |
207 |
- "_asyncio_wrapper", |
208 |
) |
209 |
|
210 |
__slots__ = _event_loop_attrs + ("_event_loop", "_is_background") |
211 |
|
212 |
diff --git a/pym/portage/util/futures/__init__.py b/pym/portage/util/futures/__init__.py |
213 |
index 0a5c103e6..bdeac90d5 100644 |
214 |
--- a/pym/portage/util/futures/__init__.py |
215 |
+++ b/pym/portage/util/futures/__init__.py |
216 |
@@ -5,7 +5,4 @@ __all__ = ( |
217 |
'asyncio', |
218 |
) |
219 |
|
220 |
-try: |
221 |
- import asyncio |
222 |
-except ImportError: |
223 |
- from portage.util.futures import _asyncio as asyncio |
224 |
+from portage.util.futures import _asyncio as asyncio |
225 |
|
226 |
diff --git a/pym/portage/util/futures/_asyncio/tasks.py b/pym/portage/util/futures/_asyncio/tasks.py |
227 |
index 392a58e64..5f10d3c7b 100644 |
228 |
--- a/pym/portage/util/futures/_asyncio/tasks.py |
229 |
+++ b/pym/portage/util/futures/_asyncio/tasks.py |
230 |
@@ -41,7 +41,6 @@ def wait(futures, loop=None, timeout=None, return_when=ALL_COMPLETED): |
231 |
@rtype: asyncio.Future (or compatible) |
232 |
""" |
233 |
loop = loop or _global_event_loop() |
234 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
235 |
result_future = loop.create_future() |
236 |
_Waiter(futures, timeout, return_when, result_future, loop) |
237 |
return result_future |
238 |
|
239 |
diff --git a/pym/portage/util/futures/executor/fork.py b/pym/portage/util/futures/executor/fork.py |
240 |
index 81c292e2c..276ed54f1 100644 |
241 |
--- a/pym/portage/util/futures/executor/fork.py |
242 |
+++ b/pym/portage/util/futures/executor/fork.py |
243 |
@@ -25,8 +25,7 @@ class ForkExecutor(object): |
244 |
""" |
245 |
def __init__(self, max_workers=None, loop=None): |
246 |
self._max_workers = max_workers or multiprocessing.cpu_count() |
247 |
- loop = loop or global_event_loop() |
248 |
- self._loop = getattr(loop, '_asyncio_wrapper', loop) |
249 |
+ self._loop = loop or global_event_loop() |
250 |
self._submit_queue = collections.deque() |
251 |
self._running_tasks = {} |
252 |
self._shutdown = False |
253 |
|
254 |
diff --git a/pym/portage/util/futures/futures.py b/pym/portage/util/futures/futures.py |
255 |
index 14ff07dee..9c9900d4c 100644 |
256 |
--- a/pym/portage/util/futures/futures.py |
257 |
+++ b/pym/portage/util/futures/futures.py |
258 |
@@ -72,7 +72,7 @@ class _EventLoopFuture(object): |
259 |
the default event loop. |
260 |
""" |
261 |
if loop is None: |
262 |
- self._loop = _global_event_loop()._asyncio_wrapper |
263 |
+ self._loop = _global_event_loop() |
264 |
else: |
265 |
self._loop = loop |
266 |
self._callbacks = [] |
267 |
|
268 |
diff --git a/pym/portage/util/futures/iter_completed.py b/pym/portage/util/futures/iter_completed.py |
269 |
index 8b0f417d9..231b7e3ab 100644 |
270 |
--- a/pym/portage/util/futures/iter_completed.py |
271 |
+++ b/pym/portage/util/futures/iter_completed.py |
272 |
@@ -31,7 +31,6 @@ def iter_completed(futures, max_jobs=None, max_load=None, loop=None): |
273 |
@rtype: iterator |
274 |
""" |
275 |
loop = loop or global_event_loop() |
276 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
277 |
|
278 |
for future_done_set in async_iter_completed(futures, |
279 |
max_jobs=max_jobs, max_load=max_load, loop=loop): |
280 |
@@ -62,7 +61,6 @@ def async_iter_completed(futures, max_jobs=None, max_load=None, loop=None): |
281 |
@rtype: iterator |
282 |
""" |
283 |
loop = loop or global_event_loop() |
284 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
285 |
|
286 |
max_jobs = max_jobs or multiprocessing.cpu_count() |
287 |
max_load = max_load or multiprocessing.cpu_count() |
288 |
@@ -136,7 +134,6 @@ def iter_gather(futures, max_jobs=None, max_load=None, loop=None): |
289 |
@rtype: asyncio.Future (or compatible) |
290 |
""" |
291 |
loop = loop or global_event_loop() |
292 |
- loop = getattr(loop, '_asyncio_wrapper', loop) |
293 |
result = loop.create_future() |
294 |
futures_list = [] |