From 2cc9ae1af1975c8c2825472e71f2a10db51d9174 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 Apr 2021 00:21:52 -1000 Subject: [PATCH] Use named constants for core shutdown timeouts (#49146) This is intended to make them easier to reference outside the core code base. --- homeassistant/core.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 6ad722e0d18..d172b3445e8 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -87,6 +87,11 @@ if TYPE_CHECKING: from homeassistant.config_entries import ConfigEntries +STAGE_1_SHUTDOWN_TIMEOUT = 120 +STAGE_2_SHUTDOWN_TIMEOUT = 60 +STAGE_3_SHUTDOWN_TIMEOUT = 30 + + block_async_io.enable() T = TypeVar("T") @@ -528,7 +533,7 @@ class HomeAssistant: self.async_track_tasks() self.bus.async_fire(EVENT_HOMEASSISTANT_STOP) try: - async with self.timeout.async_timeout(120): + async with self.timeout.async_timeout(STAGE_1_SHUTDOWN_TIMEOUT): await self.async_block_till_done() except asyncio.TimeoutError: _LOGGER.warning( @@ -539,7 +544,7 @@ class HomeAssistant: self.state = CoreState.final_write self.bus.async_fire(EVENT_HOMEASSISTANT_FINAL_WRITE) try: - async with self.timeout.async_timeout(60): + async with self.timeout.async_timeout(STAGE_2_SHUTDOWN_TIMEOUT): await self.async_block_till_done() except asyncio.TimeoutError: _LOGGER.warning( @@ -558,7 +563,7 @@ class HomeAssistant: shutdown_run_callback_threadsafe(self.loop) try: - async with self.timeout.async_timeout(30): + async with self.timeout.async_timeout(STAGE_3_SHUTDOWN_TIMEOUT): await self.async_block_till_done() except asyncio.TimeoutError: _LOGGER.warning(