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
1 changed files with 3 additions and 3 deletions

View File

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