def async_activate_callback(self, task: asyncio.Task) -> None: if task.cancelled(): log.debug(_("%s has been stopped due user request"), task.get_coro()) return exception = task.exception() if exception and not isinstance(exception, asyncio.CancelledError): stack = task.get_stack() for frame in stack: log.critical(f"{type(exception).__name__} at {frame}") log.critical(f"Fatal Error: {str(exception)}") loop = asyncio.get_running_loop() loop.stop() self.on_quit()
def stop_consuming(consume_task: asyncio.Task, task_done): try: consume_task.get_coro().throw(StopAsyncIteration) except StopIteration: pass
def get_wrapped_coroutine(t: asyncio.Task) -> Union[Coroutine, Generator]: if "safe_wrapper" in str(t): return t.get_coro().cr_frame.f_locals["c"] else: return t.get_coro()