Install a threading.excepthook on python 3.8 and later (#38741)

Exceptions in threads were being silently discarded and never
logged as the new in python 3.8 threading.excepthook was not
being set.
This commit is contained in:
J. Nick Koston 2020-08-11 02:45:36 -05:00 committed by GitHub
parent 39843319e2
commit 0d51d8660e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)