commit:     f2bece120b1e9bcd7c74fc782cef9016f2147555
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 10 06:52:58 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Apr 11 01:44:34 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f2bece12

iter_completed: support asyncio via _PortageEventLoopPolicy (bug 649588)

Support portage's internal EventLoop as well as the _PortageEventLoop
asyncio compatibility wrapper, by using the respective _loop and
_asyncio_wrapper attributes where appropriate.

Bug: https://bugs.gentoo.org/649588

 pym/portage/tests/util/futures/test_iter_completed.py | 4 ++--
 pym/portage/util/futures/iter_completed.py            | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/pym/portage/tests/util/futures/test_iter_completed.py 
b/pym/portage/tests/util/futures/test_iter_completed.py
index d0a7dbb45..9c23aefb1 100644
--- a/pym/portage/tests/util/futures/test_iter_completed.py
+++ b/pym/portage/tests/util/futures/test_iter_completed.py
@@ -29,7 +29,7 @@ class IterCompletedTestCase(TestCase):
                # load causes the tasks to finish in an unexpected order.
                self.todo = True
 
-               loop = global_event_loop()
+               loop = global_event_loop()._asyncio_wrapper
                tasks = [
                        SleepProcess(seconds=0.200),
                        SleepProcess(seconds=0.100),
@@ -41,7 +41,7 @@ class IterCompletedTestCase(TestCase):
                def future_generator():
                        for task in tasks:
                                task.future = loop.create_future()
-                               task.scheduler = loop
+                               task.scheduler = loop._loop
                                task.start()
                                yield task.future
 

diff --git a/pym/portage/util/futures/iter_completed.py 
b/pym/portage/util/futures/iter_completed.py
index ad6275b49..583a20f3b 100644
--- a/pym/portage/util/futures/iter_completed.py
+++ b/pym/portage/util/futures/iter_completed.py
@@ -30,6 +30,7 @@ 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)
        max_jobs = max_jobs or multiprocessing.cpu_count()
        max_load = max_load or multiprocessing.cpu_count()
 
@@ -43,7 +44,7 @@ def iter_completed(futures, max_jobs=None, max_load=None, 
loop=None):
                task_generator(),
                max_jobs=max_jobs,
                max_load=max_load,
-               event_loop=loop)
+               event_loop=loop._loop)
 
        try:
                scheduler.start()

Reply via email to