From a37c82e34cbf19ea4d14a3686c2437fefbaa9284 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 3 Mar 2024 07:00:35 -1000 Subject: [PATCH] Add comment to integration platform helper about blocking I/O (#112103) --- homeassistant/helpers/integration_platform.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/helpers/integration_platform.py b/homeassistant/helpers/integration_platform.py index aebbc854693..8ba0790a874 100644 --- a/homeassistant/helpers/integration_platform.py +++ b/homeassistant/helpers/integration_platform.py @@ -48,6 +48,16 @@ def _get_platform( ) return None + # + # Loading the platform may do quite a bit of blocking I/O + # and CPU work. (https://github.com/python/cpython/issues/92041) + # + # We don't want to block the event loop for too + # long so we check if the platform exists with `platform_exists` + # before trying to load it. `platform_exists` will do two + # `stat()` system calls which is far cheaper than calling + # `integration.get_platform` + # if integration.platform_exists(platform_name) is False: # If the platform cannot possibly exist, don't bother trying to load it return None