From 67858a90cdb9e5892115115fb9bf6ada64c1451d Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 8 Jan 2019 02:25:49 +0200 Subject: [PATCH] Fix #3497: Ignore done tasks when cancels pending activities on web.run_app finalization. --- aiohttp/helpers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index a44a407fea2..cbfbb1e194e 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -63,10 +63,15 @@ from typing_extensions import ContextManager -all_tasks = asyncio.Task.all_tasks +def all_tasks( + loop: Optional[asyncio.AbstractEventLoop] = None +) -> Set['asyncio.Task[Any]']: + tasks = list(asyncio.Task.all_tasks(loop)) # type: ignore + return {t for t in tasks if not t.done()} + if PY_37: - all_tasks = getattr(asyncio, 'all_tasks') # use the trick to cheat mypy + all_tasks = getattr(asyncio, 'all_tasks') # noqa _T = TypeVar('_T')