Log threading exceptions properly (#34789)
This commit is contained in:
parent
87801d8aca
commit
0246761f94
3 changed files with 32 additions and 0 deletions
26
homeassistant/util/thread.py
Normal file
26
homeassistant/util/thread.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
"""Threading util helpers."""
|
||||
import sys
|
||||
import threading
|
||||
from typing import Any
|
||||
|
||||
|
||||
def fix_threading_exception_logging() -> None:
|
||||
"""Fix threads passing uncaught exceptions to our exception hook.
|
||||
|
||||
https://bugs.python.org/issue1230540
|
||||
Fixed in Python 3.8.
|
||||
"""
|
||||
if sys.version_info[:2] >= (3, 8):
|
||||
return
|
||||
|
||||
run_old = threading.Thread.run
|
||||
|
||||
def run(*args: Any, **kwargs: Any) -> None:
|
||||
try:
|
||||
run_old(*args, **kwargs)
|
||||
except (KeyboardInterrupt, SystemExit): # pylint: disable=try-except-raise
|
||||
raise
|
||||
except Exception: # pylint: disable=broad-except
|
||||
sys.excepthook(*sys.exc_info())
|
||||
|
||||
threading.Thread.run = run # type: ignore
|
Loading…
Add table
Add a link
Reference in a new issue