mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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:
parent
cbba0fee42
commit
e54eb7e2c8
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user