Add cancel messages to core task cancelation (#96972)

This commit is contained in:
J. Nick Koston 2023-07-20 18:03:36 -05:00 committed by GitHub
parent 6818cae072
commit 99def97ed9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -764,7 +764,7 @@ class HomeAssistant:
for task in self._background_tasks: for task in self._background_tasks:
self._tasks.add(task) self._tasks.add(task)
task.add_done_callback(self._tasks.remove) task.add_done_callback(self._tasks.remove)
task.cancel() task.cancel("Home Assistant is stopping")
self._cancel_cancellable_timers() self._cancel_cancellable_timers()
self.exit_code = exit_code self.exit_code = exit_code
@ -814,7 +814,7 @@ class HomeAssistant:
"the stop event to prevent delaying shutdown", "the stop event to prevent delaying shutdown",
task, task,
) )
task.cancel() task.cancel("Home Assistant stage 2 shutdown")
try: try:
async with async_timeout.timeout(0.1): async with async_timeout.timeout(0.1):
await task await task

View File

@ -196,7 +196,7 @@ def _cancel_all_tasks_with_timeout(
return return
for task in to_cancel: for task in to_cancel:
task.cancel() task.cancel("Final process shutdown")
loop.run_until_complete(asyncio.wait(to_cancel, timeout=timeout)) loop.run_until_complete(asyncio.wait(to_cancel, timeout=timeout))

View File

@ -232,7 +232,7 @@ class _GlobalTaskContext:
"""Cancel own task.""" """Cancel own task."""
if self._task.done(): if self._task.done():
return return
self._task.cancel() self._task.cancel("Global task timeout")
def pause(self) -> None: def pause(self) -> None:
"""Pause timers while it freeze.""" """Pause timers while it freeze."""
@ -330,7 +330,7 @@ class _ZoneTaskContext:
# Timeout # Timeout
if self._task.done(): if self._task.done():
return return
self._task.cancel() self._task.cancel("Zone timeout")
def pause(self) -> None: def pause(self) -> None:
"""Pause timers while it freeze.""" """Pause timers while it freeze."""