diff options
author | Vincent Michel <vxgmichel@gmail.com> | 2019-11-19 13:53:52 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-11-19 13:53:52 (GMT) |
commit | 8e0de2a4808d7c2f4adedabff89ee64e0338790a (patch) | |
tree | 745ce6bba5ebdb82a1ab7d739b218674fe29b35b /Lib/test | |
parent | f25875af425a3480e557aaedf49c3bb867bcbd5d (diff) | |
download | cpython-8e0de2a4808d7c2f4adedabff89ee64e0338790a.zip cpython-8e0de2a4808d7c2f4adedabff89ee64e0338790a.tar.gz cpython-8e0de2a4808d7c2f4adedabff89ee64e0338790a.tar.bz2 |
bpo-35409: Ignore GeneratorExit in async_gen_athrow_throw (GH-14755)
Ignore `GeneratorExit` exceptions when throwing an exception into the `aclose` coroutine of an asynchronous generator.
https://bugs.python.org/issue35409
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncgen.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index 23eb6a4..58d8aee 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -735,6 +735,33 @@ class AsyncGenAsyncioTest(unittest.TestCase): self.loop.run_until_complete(run()) self.assertEqual(DONE, 10) + def test_async_gen_asyncio_aclose_12(self): + DONE = 0 + + async def target(): + await asyncio.sleep(0.01) + 1 / 0 + + async def foo(): + nonlocal DONE + task = asyncio.create_task(target()) + try: + yield 1 + finally: + try: + await task + except ZeroDivisionError: + DONE = 1 + + async def run(): + gen = foo() + it = gen.__aiter__() + await it.__anext__() + await gen.aclose() + + self.loop.run_until_complete(run()) + self.assertEqual(DONE, 1) + def test_async_gen_asyncio_asend_01(self): DONE = 0 |