commit: 25245d7eb86ed197b7d7cfead0dbe4ce8ad4bc5b
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 19 06:13:33 2018 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Apr 19 06:13:33 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=25245d7e
EventLoop.run_until_complete: wait for done callbacks
Since done callbacks are executed via call_soon, it's desirable to
continue iterating until those callbacks have executed, which is easily
achieved by registering a done callback and waiting for it to execute.
pym/portage/util/_eventloop/EventLoop.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/pym/portage/util/_eventloop/EventLoop.py
b/pym/portage/util/_eventloop/EventLoop.py
index 7208c3aa1..33fae26f2 100644
--- a/pym/portage/util/_eventloop/EventLoop.py
+++ b/pym/portage/util/_eventloop/EventLoop.py
@@ -812,7 +812,14 @@ class EventLoop(object):
@raise: the Future's exception
"""
future = asyncio.ensure_future(future,
loop=self._asyncio_wrapper)
- while not future.done():
+
+ # Since done callbacks are executed via call_soon, it's
desirable
+ # to continue iterating until those callbacks have executed,
which
+ # is easily achieved by registering a done callback and waiting
for
+ # it to execute.
+ waiter = self.create_future()
+ future.add_done_callback(functools.partial(waiter.set_result))
+ while not waiter.done():
self.iteration()
return future.result()