From ef6a6c9497e74fc7a0a928e8f097cc566b73d1d6 Mon Sep 17 00:00:00 2001 From: Krzysztof Warunek Date: Fri, 15 Sep 2017 01:18:20 +0200 Subject: [PATCH 1/3] bpo-31452: fix asyncio.gather does not cancel tasks if one fails --- Lib/asyncio/tasks.py | 1 + Lib/test/test_asyncio/test_tasks.py | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) 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) From 38bfafc1347d11abaf1a17b0976bbab0b4cab12c Mon Sep 17 00:00:00 2001 From: Krzysztof Warunek Date: Tue, 19 Sep 2017 09:47:50 +0200 Subject: [PATCH 2/3] update NEWS --- .../next/Library/2017-09-19-09-32-23.bpo-31452.pudGAN.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-09-19-09-32-23.bpo-31452.pudGAN.rst 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..238a165c17ca14 --- /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 From aec0d55b944305eb2d47089cedf48f653ca413f0 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 20 Sep 2017 11:56:34 +0300 Subject: [PATCH 3/3] Update 2017-09-19-09-32-23.bpo-31452.pudGAN.rst --- .../next/Library/2017-09-19-09-32-23.bpo-31452.pudGAN.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 238a165c17ca14..ab0c81c9b50517 100644 --- 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 @@ -1,2 +1,2 @@ -`asyncio.gather` (without return_exceptions) should cancel pending tasks if +asyncio.gather() (without return_exceptions) should cancel pending tasks if one fails