commit:     b37256a524a0fbf88ffad20c9f01aaf37409ec66
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Sep  3 20:16:37 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Sep  3 20:20:40 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=b37256a5

compat_coroutine: CancelledError cancels coroutine's future

 lib/portage/tests/util/futures/test_compat_coroutine.py | 8 ++++++--
 lib/portage/util/futures/compat_coroutine.py            | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/portage/tests/util/futures/test_compat_coroutine.py 
b/lib/portage/tests/util/futures/test_compat_coroutine.py
index cbc070869..b6f75b1a2 100644
--- a/lib/portage/tests/util/futures/test_compat_coroutine.py
+++ b/lib/portage/tests/util/futures/test_compat_coroutine.py
@@ -71,6 +71,10 @@ class CompatCoroutineTestCase(TestCase):
                        loop.run_until_complete, future)
 
        def test_cancelled_future(self):
+               """
+               When a coroutine raises CancelledError, the coroutine's
+               future is cancelled.
+               """
 
                @coroutine
                def cancelled_future_coroutine(loop=None):
@@ -81,8 +85,8 @@ class CompatCoroutineTestCase(TestCase):
                                yield future
 
                loop = asyncio.get_event_loop()
-               self.assertRaises(asyncio.CancelledError,
-                       loop.run_until_complete, 
cancelled_future_coroutine(loop=loop))
+               future = 
loop.run_until_complete(asyncio.wait([cancelled_future_coroutine()]))[0].pop()
+               self.assertTrue(future.cancelled())
 
        def test_yield_expression_result(self):
                @coroutine

diff --git a/lib/portage/util/futures/compat_coroutine.py 
b/lib/portage/util/futures/compat_coroutine.py
index 59fdc31b6..3edfa6bee 100644
--- a/lib/portage/util/futures/compat_coroutine.py
+++ b/lib/portage/util/futures/compat_coroutine.py
@@ -102,6 +102,8 @@ class _GeneratorTask(object):
                                self._generator.throw(previous.exception())
                                future = next(self._generator)
 
+               except asyncio.CancelledError:
+                       self._result.cancel()
                except _CoroutineReturnValue as e:
                        if not self._result.cancelled():
                                self._result.set_result(e.result)

Reply via email to