commit: 82a3cda6f1ffbbbd75c962d610c7eb4a04a865d9 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Sat May 5 21:00:51 2018 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Sat May 5 21:00:51 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=82a3cda6
Minimize _asyncio_wrapper usage (bug 654390) Since migration to asyncio compatible APIs is now complete, minimize _asyncio_wrapper usage. Also remove _asyncio_wrapper from SchedulerInterface, since there are no more consumers. Bug: https://bugs.gentoo.org/654390 pym/_emerge/AbstractPollTask.py | 2 +- pym/portage/_emirrordist/FetchIterator.py | 1 - pym/portage/dbapi/porttree.py | 3 --- .../tests/util/futures/asyncio/test_subprocess_exec.py | 1 - pym/portage/tests/util/futures/test_iter_completed.py | 4 ++-- pym/portage/tests/util/futures/test_retry.py | 16 ++++++++-------- pym/portage/util/_async/SchedulerInterface.py | 1 - pym/portage/util/futures/__init__.py | 5 +---- pym/portage/util/futures/_asyncio/tasks.py | 1 - pym/portage/util/futures/executor/fork.py | 3 +-- pym/portage/util/futures/futures.py | 2 +- pym/portage/util/futures/iter_completed.py | 3 --- 12 files changed, 14 insertions(+), 28 deletions(-) diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py index dff4b3efd..f898aa708 100644 --- a/pym/_emerge/AbstractPollTask.py +++ b/pym/_emerge/AbstractPollTask.py @@ -109,7 +109,7 @@ class AbstractPollTask(AsynchronousTask): self._registered = False def _wait_loop(self, timeout=None): - loop = getattr(self.scheduler, '_asyncio_wrapper', self.scheduler) + loop = self.scheduler tasks = [self.async_wait()] if timeout is not None: tasks.append(asyncio.ensure_future( diff --git a/pym/portage/_emirrordist/FetchIterator.py b/pym/portage/_emirrordist/FetchIterator.py index 366453c12..04d4da62b 100644 --- a/pym/portage/_emirrordist/FetchIterator.py +++ b/pym/portage/_emirrordist/FetchIterator.py @@ -125,7 +125,6 @@ def _async_fetch_tasks(config, hash_filter, repo_config, digests_future, cpv, instances for each of the files referenced by an ebuild. @rtype: asyncio.Future (or compatible) """ - loop = getattr(loop, '_asyncio_wrapper', loop) result = loop.create_future() fetch_tasks = [] diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 6c38232bb..801b5658a 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -612,7 +612,6 @@ class portdbapi(dbapi): # Callers of this method certainly want the same event loop to # be used for all calls. loop = loop or global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) future = loop.create_future() cache_me = False if myrepo is not None: @@ -753,7 +752,6 @@ class portdbapi(dbapi): @rtype: asyncio.Future (or compatible) """ loop = loop or global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) result = loop.create_future() def aux_get_done(aux_get_future): @@ -1422,7 +1420,6 @@ def _async_manifest_fetchlist(portdb, repo_config, cp, cpv_list=None, @rtype: asyncio.Future (or compatible) """ loop = loop or global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) result = loop.create_future() cpv_list = (portdb.cp_list(cp, mytree=repo_config.location) if cpv_list is None else cpv_list) diff --git a/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py b/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py index be103a9e0..98983941d 100644 --- a/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py +++ b/pym/portage/tests/util/futures/asyncio/test_subprocess_exec.py @@ -24,7 +24,6 @@ def reader(input_file, loop=None): @rtype: asyncio.Future (or compatible) """ loop = loop or asyncio.get_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) future = loop.create_future() _Reader(future, input_file, loop) return future diff --git a/pym/portage/tests/util/futures/test_iter_completed.py b/pym/portage/tests/util/futures/test_iter_completed.py index 90668eb02..9ab410a9e 100644 --- a/pym/portage/tests/util/futures/test_iter_completed.py +++ b/pym/portage/tests/util/futures/test_iter_completed.py @@ -34,7 +34,7 @@ class IterCompletedTestCase(TestCase): # load causes the tasks to finish in an unexpected order. self.todo = True - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() tasks = [ SleepProcess(seconds=0.200), SleepProcess(seconds=0.100), @@ -56,7 +56,7 @@ class IterCompletedTestCase(TestCase): def testAsyncCancel(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() input_futures = set() future_count = 3 diff --git a/pym/portage/tests/util/futures/test_retry.py b/pym/portage/tests/util/futures/test_retry.py index 27d8c7b61..cdca7d294 100644 --- a/pym/portage/tests/util/futures/test_retry.py +++ b/pym/portage/tests/util/futures/test_retry.py @@ -56,7 +56,7 @@ class HangForever(object): class RetryTestCase(TestCase): def testSucceedLater(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = SucceedLater(1) func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(try_max=9999, @@ -66,7 +66,7 @@ class RetryTestCase(TestCase): self.assertEqual(result, 'success') def testSucceedNever(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = SucceedNever() func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(try_max=4, try_timeout=None, @@ -77,7 +77,7 @@ class RetryTestCase(TestCase): self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) def testSucceedNeverReraise(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = SucceedNever() func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(reraise=True, try_max=4, try_timeout=None, @@ -88,7 +88,7 @@ class RetryTestCase(TestCase): self.assertTrue(isinstance(done.pop().exception(), SucceedNeverException)) def testHangForever(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = HangForever() func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(try_max=2, try_timeout=0.1, @@ -99,7 +99,7 @@ class RetryTestCase(TestCase): self.assertTrue(isinstance(done.pop().exception().__cause__, asyncio.TimeoutError)) def testHangForeverReraise(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = HangForever() func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(reraise=True, try_max=2, try_timeout=0.1, @@ -110,7 +110,7 @@ class RetryTestCase(TestCase): self.assertTrue(isinstance(done.pop().exception(), asyncio.TimeoutError)) def testCancelRetry(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = SucceedNever() func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(try_timeout=0.1, @@ -123,7 +123,7 @@ class RetryTestCase(TestCase): self.assertTrue(done.pop().cancelled()) def testOverallTimeoutWithException(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() func = SucceedNever() func_coroutine = functools.partial(loop.run_in_executor, None, func) decorator = retry(try_timeout=0.1, overall_timeout=0.3, @@ -134,7 +134,7 @@ class RetryTestCase(TestCase): self.assertTrue(isinstance(done.pop().exception().__cause__, SucceedNeverException)) def testOverallTimeoutWithTimeoutError(self): - loop = global_event_loop()._asyncio_wrapper + loop = global_event_loop() # results in TimeoutError because it hangs forever func = HangForever() func_coroutine = functools.partial(loop.run_in_executor, None, func) diff --git a/pym/portage/util/_async/SchedulerInterface.py b/pym/portage/util/_async/SchedulerInterface.py index 718fbc8e7..f1a3e9b0b 100644 --- a/pym/portage/util/_async/SchedulerInterface.py +++ b/pym/portage/util/_async/SchedulerInterface.py @@ -33,7 +33,6 @@ class SchedulerInterface(SlotObject): "time", "_asyncio_child_watcher", - "_asyncio_wrapper", ) __slots__ = _event_loop_attrs + ("_event_loop", "_is_background") diff --git a/pym/portage/util/futures/__init__.py b/pym/portage/util/futures/__init__.py index 0a5c103e6..bdeac90d5 100644 --- a/pym/portage/util/futures/__init__.py +++ b/pym/portage/util/futures/__init__.py @@ -5,7 +5,4 @@ __all__ = ( 'asyncio', ) -try: - import asyncio -except ImportError: - from portage.util.futures import _asyncio as asyncio +from portage.util.futures import _asyncio as asyncio diff --git a/pym/portage/util/futures/_asyncio/tasks.py b/pym/portage/util/futures/_asyncio/tasks.py index 392a58e64..5f10d3c7b 100644 --- a/pym/portage/util/futures/_asyncio/tasks.py +++ b/pym/portage/util/futures/_asyncio/tasks.py @@ -41,7 +41,6 @@ def wait(futures, loop=None, timeout=None, return_when=ALL_COMPLETED): @rtype: asyncio.Future (or compatible) """ loop = loop or _global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) result_future = loop.create_future() _Waiter(futures, timeout, return_when, result_future, loop) return result_future diff --git a/pym/portage/util/futures/executor/fork.py b/pym/portage/util/futures/executor/fork.py index 81c292e2c..276ed54f1 100644 --- a/pym/portage/util/futures/executor/fork.py +++ b/pym/portage/util/futures/executor/fork.py @@ -25,8 +25,7 @@ class ForkExecutor(object): """ def __init__(self, max_workers=None, loop=None): self._max_workers = max_workers or multiprocessing.cpu_count() - loop = loop or global_event_loop() - self._loop = getattr(loop, '_asyncio_wrapper', loop) + self._loop = loop or global_event_loop() self._submit_queue = collections.deque() self._running_tasks = {} self._shutdown = False diff --git a/pym/portage/util/futures/futures.py b/pym/portage/util/futures/futures.py index 14ff07dee..9c9900d4c 100644 --- a/pym/portage/util/futures/futures.py +++ b/pym/portage/util/futures/futures.py @@ -72,7 +72,7 @@ class _EventLoopFuture(object): the default event loop. """ if loop is None: - self._loop = _global_event_loop()._asyncio_wrapper + self._loop = _global_event_loop() else: self._loop = loop self._callbacks = [] diff --git a/pym/portage/util/futures/iter_completed.py b/pym/portage/util/futures/iter_completed.py index 8b0f417d9..231b7e3ab 100644 --- a/pym/portage/util/futures/iter_completed.py +++ b/pym/portage/util/futures/iter_completed.py @@ -31,7 +31,6 @@ def iter_completed(futures, max_jobs=None, max_load=None, loop=None): @rtype: iterator """ loop = loop or global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) for future_done_set in async_iter_completed(futures, max_jobs=max_jobs, max_load=max_load, loop=loop): @@ -62,7 +61,6 @@ def async_iter_completed(futures, max_jobs=None, max_load=None, loop=None): @rtype: iterator """ loop = loop or global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) max_jobs = max_jobs or multiprocessing.cpu_count() max_load = max_load or multiprocessing.cpu_count() @@ -136,7 +134,6 @@ def iter_gather(futures, max_jobs=None, max_load=None, loop=None): @rtype: asyncio.Future (or compatible) """ loop = loop or global_event_loop() - loop = getattr(loop, '_asyncio_wrapper', loop) result = loop.create_future() futures_list = []
