diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 575d205404ae39..cee806f1035354 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -625,6 +625,7 @@ def _done_callback(i, fut): elif fut._exception is not None: res = fut.exception() # Mark exception retrieved. if not return_exceptions: + outer.cancel() outer.set_exception(res) return else: diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 36082ec7c6a79a..7186238e8b6526 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2234,10 +2234,9 @@ def test_one_exception(self): cb.assert_called_once_with(fut) self.assertIs(fut.exception(), exc) # Does nothing - c.set_result(3) - d.cancel() - e.set_exception(RuntimeError()) - e.exception() + self.assertTrue(c.cancelled()) + self.assertTrue(d.cancelled()) + self.assertTrue(e.cancelled()) def test_return_exceptions(self): a, b, c, d = [asyncio.Future(loop=self.one_loop) for i in range(4)] @@ -2465,7 +2464,7 @@ def outer(): test_utils.run_briefly(self.one_loop) a.set_result(None) test_utils.run_briefly(self.one_loop) - b.set_result(None) + self.assertTrue(b.cancelled()) test_utils.run_briefly(self.one_loop) self.assertIsInstance(f.exception(), RuntimeError) diff --git a/Misc/NEWS.d/next/Library/2017-09-19-09-32-23.bpo-31452.pudGAN.rst b/Misc/NEWS.d/next/Library/2017-09-19-09-32-23.bpo-31452.pudGAN.rst new file mode 100644 index 00000000000000..ab0c81c9b50517 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-09-19-09-32-23.bpo-31452.pudGAN.rst @@ -0,0 +1,2 @@ +asyncio.gather() (without return_exceptions) should cancel pending tasks if +one fails