Skip to content

Commit

Permalink
Install a threading.excepthook on python 3.8 and later (#38741)
Browse files Browse the repository at this point in the history
Exceptions in threads were being silently discarded and never
logged as the new in python 3.8 threading.excepthook was not
being set.
  • Loading branch information
bdraco authored and frenck committed Aug 12, 2020
1 parent 4861753 commit eada72e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions homeassistant/bootstrap.py
Expand Up @@ -6,6 +6,7 @@
import logging.handlers
import os
import sys
import threading
from time import monotonic
from typing import TYPE_CHECKING, Any, Dict, Optional, Set

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eada72e

Please sign in to comment.