From adee8094e78fd30e6965a34efcd36a7013afe13b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 5 Jul 2024 01:30:07 -0500 Subject: [PATCH] Cache is_official_image/is_docker_env in bootstrap to fix blocking I/O (#121261) * Cache is_official_image and is_docker_env in bootstrap to fix blocking I/O These do blocking I/O later in the startup process discovered in https://github.com/home-assistant/core/pull/120273 * comment --- homeassistant/bootstrap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index c5229634053..f4cfc8c87c8 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -88,7 +88,7 @@ from .helpers import ( ) from .helpers.dispatcher import async_dispatcher_send_internal from .helpers.storage import get_internal_store_manager -from .helpers.system_info import async_get_system_info +from .helpers.system_info import async_get_system_info, is_official_image from .helpers.typing import ConfigType from .setup import ( # _setup_started is marked as protected to make it clear @@ -104,7 +104,7 @@ from .setup import ( from .util.async_ import create_eager_task from .util.hass_dict import HassKey from .util.logging import async_activate_log_queue_handler -from .util.package import async_get_user_site, is_virtual_env +from .util.package import async_get_user_site, is_docker_env, is_virtual_env with contextlib.suppress(ImportError): # Ensure anyio backend is imported to avoid it being imported in the event loop @@ -407,6 +407,10 @@ def _init_blocking_io_modules_in_executor() -> None: # Initialize the mimetypes module to avoid blocking calls # to the filesystem to load the mime.types file. mimetypes.init() + # Initialize is_official_image and is_docker_env to avoid blocking calls + # to the filesystem. + is_official_image() + is_docker_env() async def async_load_base_functionality(hass: core.HomeAssistant) -> None: