diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 4cf95d68f05..a7953cbec6c 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -6,6 +6,7 @@ import logging import logging.handlers import os import sys +import threading from time import monotonic from typing import TYPE_CHECKING, Any, Dict, Optional, Set @@ -308,6 +309,12 @@ def async_enable_logging( "Uncaught exception", exc_info=args # type: ignore ) + if sys.version_info[:2] >= (3, 8): + threading.excepthook = lambda args: logging.getLogger(None).exception( + "Uncaught thread exception", + exc_info=(args.exc_type, args.exc_value, args.exc_traceback), + ) + # Log errors to a file if we have write access to file or config dir if log_file is None: err_log_path = hass.config.path(ERROR_LOG_FILENAME)