File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 5252from functools import partial
5353from abc import abstractmethod , ABC
5454import enum
55- from contextlib import nullcontext
55+ from contextlib import nullcontext , suppress
5656import traceback
5757import inspect
5858
@@ -1704,8 +1704,20 @@ def run_event_loop():
17041704 loop .run_until_complete (stopping_fut )
17051705 finally :
17061706 # clean-up
1707+ try :
1708+ pending_tasks = asyncio .gather (* asyncio .all_tasks (loop ), return_exceptions = True )
1709+ pending_tasks .cancel ()
1710+ with suppress (asyncio .CancelledError ):
1711+ loop .run_until_complete (pending_tasks )
1712+ loop .run_until_complete (loop .shutdown_asyncgens ())
1713+ if isinstance (loop , asyncio .BaseEventLoop ):
1714+ loop .run_until_complete (loop .shutdown_default_executor ())
1715+ except Exception as e :
1716+ _logger .debug (f"exception when cleaning up asyncio event loop: { e } " )
1717+
17071718 global _asyncio_event_loop
17081719 _asyncio_event_loop = None
1720+ loop .close ()
17091721
17101722 loop .set_exception_handler (on_exception )
17111723 _set_custom_task_factory (loop )
You can’t perform that action at this time.
0 commit comments