Log which task is blocking startup when debug logging is on (#38134)
* Log which task is blocking startup when debug logging for homeassistant.core is on * test needs to go one level deeper now
This commit is contained in:
1 parent
24b8545ebe
commit
979dafd0a7
3 files changed
+39
-3
No files matched your search
+16
-1
@@ -23,6 +23,7 @@ from typing import (
|
||||
Callable,
|
||||
Coroutine,
|
||||
Dict,
|
||||
Iterable,
|
||||
List,
|
||||
Mapping,
|
||||
Optional,
|
||||
@@ -98,6 +99,9 @@ CORE_STORAGE_VERSION = 1
|
||||
|
||||
DOMAIN = "homeassistant"
|
||||
|
||||
# How long to wait to log tasks that are blocking
|
||||
BLOCK_LOG_TIMEOUT = 60
|
||||
|
||||
# How long we wait for the result of a service call
|
||||
SERVICE_CALL_LIMIT = 10 # seconds
|
||||
|
||||
@@ -393,10 +397,21 @@ class HomeAssistant:
|
||||
pending = [task for task in self._pending_tasks if not task.done()]
|
||||
self._pending_tasks.clear()
|
||||
if pending:
|
||||
await asyncio.wait(pending)
|
||||
await self._await_and_log_pending(pending)
|
||||
else:
|
||||
await asyncio.sleep(0)
|
||||
|
||||
async def _await_and_log_pending(self, pending: Iterable[Awaitable[Any]]) -> None:
|
||||
"""Await and log tasks that take a long time."""
|
||||
wait_time = 0
|
||||
while pending:
|
||||
_, pending = await asyncio.wait(pending, timeout=BLOCK_LOG_TIMEOUT)
|
||||
if not pending:
|
||||
return
|
||||
wait_time += BLOCK_LOG_TIMEOUT
|
||||
for task in pending:
|
||||
_LOGGER.debug("Waited %s seconds for task: %s", wait_time, task)
|
||||
|
||||
def stop(self) -> None:
|
||||
"""Stop Home Assistant and shuts down all threads."""
|
||||
if self.state == CoreState.not_running: # just ignore
|
||||
|
||||
Reference in new issue
Block a user