Switch shell_command to use async_timeout instead of asyncio.wait_for (#88573)

This avoids creating a task every time
This commit is contained in:
J. Nick Koston 2023-02-21 20:11:54 -06:00 committed by GitHub
parent cbba0fee42
commit e54eb7e2c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ from contextlib import suppress
import logging import logging
import shlex import shlex
import async_timeout
import voluptuous as vol import voluptuous as vol
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
@ -82,9 +83,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
process = await create_process process = await create_process
try: try:
stdout_data, stderr_data = await asyncio.wait_for( async with async_timeout.timeout(COMMAND_TIMEOUT):
process.communicate(), COMMAND_TIMEOUT stdout_data, stderr_data = await process.communicate()
)
except asyncio.TimeoutError: except asyncio.TimeoutError:
_LOGGER.exception( _LOGGER.exception(
"Timed out running command: `%s`, after: %ss", cmd, COMMAND_TIMEOUT "Timed out running command: `%s`, after: %ss", cmd, COMMAND_TIMEOUT