Improve thread safety check messages to better convey impact (#117467)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
pull/117471/head
J. Nick Koston 2024-05-15 13:49:57 +09:00 committed by GitHub
parent 8f9273e945
commit d29084d6fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -439,7 +439,8 @@ class HomeAssistant:
# frame is a circular import, so we import it here
frame.report(
f"calls {what} from a thread. "
f"calls {what} from a thread other than the event loop, "
"which may cause Home Assistant to crash or data to corrupt. "
"For more information, see "
"https://developers.home-assistant.io/docs/asyncio_thread_safety/"
f"#{what.replace('.', '')}",

View File

@ -9,6 +9,7 @@ import functools
import gc
import logging
import os
import re
from tempfile import TemporaryDirectory
import threading
import time
@ -3486,3 +3487,18 @@ async def test_async_create_task_thread_safety(hass: HomeAssistant) -> None:
match="Detected code that calls hass.async_create_task from a thread.",
):
await hass.async_add_executor_job(hass.async_create_task, _any_coro)
async def test_thread_safety_message(hass: HomeAssistant) -> None:
"""Test the thread safety message."""
with pytest.raises(
RuntimeError,
match=re.escape(
"Detected code that calls test from a thread other than the event loop, "
"which may cause Home Assistant to crash or data to corrupt. For more "
"information, see "
"https://developers.home-assistant.io/docs/asyncio_thread_safety/#test"
". Please report this issue.",
),
):
await hass.async_add_executor_job(hass.verify_event_loop_thread, "test")