Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _cancel_all_tasks(loop: asyncio.AbstractEventLoop) -> None:
- tasks = [task for task in asyncio.all_tasks(loop) if not task.done()]
- if not tasks:
- return
- for task in tasks:
- task.cancel()
- loop.run_until_complete(asyncio.gather(*tasks, loop=loop, return_exceptions=True))
- for task in tasks:
- if not task.cancelled() and task.exception() is not None:
- loop.call_exception_handler(
- {
- "message": "unhandled exception during shutdown",
- "exception": task.exception(),
- "task": task,
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement