From ca4d7634a8b907e4d19ec85efee259a4336de180 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 21 Jan 2023 12:02:03 -1000 Subject: [PATCH] Switch an `asyncio.wait_for` in the template helper to `async_timeout` (#86349) Switch an asyncio.wait_for in the template helper to async_timeout Eliminates the extra task when calling async_render_will_timeout --- homeassistant/helpers/template.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index d938b9771a4..1a4aaf39b19 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -24,6 +24,7 @@ from typing import Any, Literal, NoReturn, TypeVar, cast, overload from urllib.parse import urlencode as urllib_urlencode import weakref +import async_timeout from awesomeversion import AwesomeVersion import jinja2 from jinja2 import pass_context, pass_environment, pass_eval_context @@ -534,7 +535,8 @@ class Template: try: template_render_thread = ThreadWithException(target=_render_template) template_render_thread.start() - await asyncio.wait_for(finish_event.wait(), timeout=timeout) + async with async_timeout.timeout(timeout): + await finish_event.wait() if self._exc_info: raise TemplateError(self._exc_info[1].with_traceback(self._exc_info[2])) except asyncio.TimeoutError: