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
This commit is contained in:
J. Nick Koston 2024-07-05 01:30:07 -05:00 committed by GitHub
parent 6c42596bdd
commit adee8094e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,7 +88,7 @@ from .helpers import (
) )
from .helpers.dispatcher import async_dispatcher_send_internal from .helpers.dispatcher import async_dispatcher_send_internal
from .helpers.storage import get_internal_store_manager 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 .helpers.typing import ConfigType
from .setup import ( from .setup import (
# _setup_started is marked as protected to make it clear # _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.async_ import create_eager_task
from .util.hass_dict import HassKey from .util.hass_dict import HassKey
from .util.logging import async_activate_log_queue_handler 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): with contextlib.suppress(ImportError):
# Ensure anyio backend is imported to avoid it being imported in the event loop # 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 # Initialize the mimetypes module to avoid blocking calls
# to the filesystem to load the mime.types file. # to the filesystem to load the mime.types file.
mimetypes.init() 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: async def async_load_base_functionality(hass: core.HomeAssistant) -> None: