mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Import stream in the executor to avoid blocking the event loop (#112078)
* Import stream in the executor to avoid blocking the event loop This one has some large deps * one more place * avoid call if no change * just in case
This commit is contained in:
parent
aaa2d8745f
commit
dc3c7c95f7
@ -188,22 +188,26 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
def set_pyav_logging(enable: bool) -> None:
|
||||||
def update_pyav_logging(_event: Event | None = None) -> None:
|
|
||||||
"""Adjust libav logging to only log when the stream logger is at DEBUG."""
|
|
||||||
|
|
||||||
def set_pyav_logging(enable: bool) -> None:
|
|
||||||
"""Turn PyAV logging on or off."""
|
"""Turn PyAV logging on or off."""
|
||||||
import av # pylint: disable=import-outside-toplevel
|
import av # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
av.logging.set_level(av.logging.VERBOSE if enable else av.logging.FATAL)
|
av.logging.set_level(av.logging.VERBOSE if enable else av.logging.FATAL)
|
||||||
|
|
||||||
# enable PyAV logging iff Stream logger is set to debug
|
|
||||||
set_pyav_logging(logging.getLogger(__name__).isEnabledFor(logging.DEBUG))
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up stream."""
|
"""Set up stream."""
|
||||||
|
debug_enabled = _LOGGER.isEnabledFor(logging.DEBUG)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def update_pyav_logging(_event: Event | None = None) -> None:
|
||||||
|
"""Adjust libav logging to only log when the stream logger is at DEBUG."""
|
||||||
|
nonlocal debug_enabled
|
||||||
|
if (new_debug_enabled := _LOGGER.isEnabledFor(logging.DEBUG)) == debug_enabled:
|
||||||
|
return
|
||||||
|
debug_enabled = new_debug_enabled
|
||||||
|
# enable PyAV logging iff Stream logger is set to debug
|
||||||
|
set_pyav_logging(new_debug_enabled)
|
||||||
|
|
||||||
# Only pass through PyAV log messages if stream logging is above DEBUG
|
# Only pass through PyAV log messages if stream logging is above DEBUG
|
||||||
cancel_logging_listener = hass.bus.async_listen(
|
cancel_logging_listener = hass.bus.async_listen(
|
||||||
@ -213,7 +217,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
# at logging.WARNING. Set those Logger levels to logging.ERROR
|
# at logging.WARNING. Set those Logger levels to logging.ERROR
|
||||||
for logging_namespace in ("libav.mp4", "libav.swscaler"):
|
for logging_namespace in ("libav.mp4", "libav.swscaler"):
|
||||||
logging.getLogger(logging_namespace).setLevel(logging.ERROR)
|
logging.getLogger(logging_namespace).setLevel(logging.ERROR)
|
||||||
update_pyav_logging()
|
|
||||||
|
# This will load av so we run it in the executor
|
||||||
|
await hass.async_add_import_executor_job(set_pyav_logging, debug_enabled)
|
||||||
|
|
||||||
# Keep import here so that we can import stream integration without installing reqs
|
# Keep import here so that we can import stream integration without installing reqs
|
||||||
# pylint: disable-next=import-outside-toplevel
|
# pylint: disable-next=import-outside-toplevel
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"codeowners": ["@hunterjm", "@uvjustin", "@allenporter"],
|
"codeowners": ["@hunterjm", "@uvjustin", "@allenporter"],
|
||||||
"dependencies": ["http"],
|
"dependencies": ["http"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/stream",
|
"documentation": "https://www.home-assistant.io/integrations/stream",
|
||||||
|
"import_executor": true,
|
||||||
"integration_type": "system",
|
"integration_type": "system",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"quality_scale": "internal",
|
"quality_scale": "internal",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user