From c382fd8198180796dfe11b5b6ff7c4679725efad Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 13 Jul 2022 08:49:16 -0800 Subject: [PATCH] fix(tasks): cancel all the pending tasks as we exit own loop (#1430) --- playwright/sync_api/_context_manager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/playwright/sync_api/_context_manager.py b/playwright/sync_api/_context_manager.py index 318aab4bb..0fe9b552b 100644 --- a/playwright/sync_api/_context_manager.py +++ b/playwright/sync_api/_context_manager.py @@ -98,5 +98,8 @@ def __exit__(self, *args: Any) -> None: if self._watcher: self._watcher.close() if self._own_loop: + tasks = asyncio.all_tasks(self._loop) + for t in [t for t in tasks if not (t.done() or t.cancelled())]: + t.cancel() self._loop.run_until_complete(self._loop.shutdown_asyncgens()) self._loop.close()