Log unhandled loop exception traces when asyncio debug is on (#57602)

This commit is contained in:
J. Nick Koston
2021-10-18 17:07:51 -10:00
committed by GitHub
parent f92fe38bbd
commit 6576225c48
3 changed files with 36 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import asyncio
import dataclasses
import logging
import threading
import traceback
from typing import Any
from homeassistant import bootstrap
@@ -86,9 +87,15 @@ def _async_loop_exception_handler(_: Any, context: dict[str, Any]) -> None:
if exception := context.get("exception"):
kwargs["exc_info"] = (type(exception), exception, exception.__traceback__)
logging.getLogger(__package__).error(
"Error doing job: %s", context["message"], **kwargs # type: ignore
)
logger = logging.getLogger(__package__)
if source_traceback := context.get("source_traceback"):
stack_summary = "".join(traceback.format_list(source_traceback))
logger.error(
"Error doing job: %s: %s", context["message"], stack_summary, **kwargs # type: ignore
)
return
logger.error("Error doing job: %s", context["message"], **kwargs) # type: ignore
async def setup_and_run_hass(runtime_config: RuntimeConfig) -> int: