Improve performance of verify_event_loop_thread (#118198)
This commit is contained in:
parent
87fc27eeae
commit
25f199c39c
2 changed files with 5 additions and 3 deletions
|
@ -434,12 +434,13 @@ class HomeAssistant:
|
|||
self.import_executor = InterruptibleThreadPoolExecutor(
|
||||
max_workers=1, thread_name_prefix="ImportExecutor"
|
||||
)
|
||||
self._loop_thread_id = getattr(
|
||||
self.loop, "_thread_ident", getattr(self.loop, "_thread_id")
|
||||
)
|
||||
|
||||
def verify_event_loop_thread(self, what: str) -> None:
|
||||
"""Report and raise if we are not running in the event loop thread."""
|
||||
if (
|
||||
loop_thread_ident := self.loop.__dict__.get("_thread_ident")
|
||||
) and loop_thread_ident != threading.get_ident():
|
||||
if self._loop_thread_id != threading.get_ident():
|
||||
from .helpers import frame # pylint: disable=import-outside-toplevel
|
||||
|
||||
# frame is a circular import, so we import it here
|
||||
|
|
|
@ -174,6 +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
|
||||
loop.run_forever()
|
||||
loop_stop_event.set()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue