1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Always do thread safety check when writing state (#118886)

* Always do thread safety check when writing state

Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.

Previously the check was limited to custom components
because they were the most common source of thread
safety issues.

* Always do thread safety check when writing state

Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.

Previously the check was limited to custom components
because they were the most common source of thread
safety issues.

* async_fire is more common than expected with ccs

* fix mock

* fix hass mocking
This commit is contained in:
J. Nick Koston
2024-06-05 22:41:55 -05:00
committed by GitHub
parent 64b23419e0
commit 475c20d529
6 changed files with 34 additions and 33 deletions

View File

@@ -174,7 +174,7 @@ def get_test_home_assistant() -> Generator[HomeAssistant, None, None]:
"""Run event loop."""
loop._thread_ident = threading.get_ident()
hass._loop_thread_id = loop._thread_ident
hass.loop_thread_id = loop._thread_ident
loop.run_forever()
loop_stop_event.set()