cannot chain

pull/112640/head
J. Nick Koston 2024-03-07 11:56:26 -10:00
parent 441573ce70
commit 1d8708ded3
No known key found for this signature in database
1 changed files with 6 additions and 7 deletions

View File

@ -23,7 +23,6 @@ import datetime
import enum
import functools
import inspect
from itertools import chain
import logging
import os
import pathlib
@ -843,13 +842,13 @@ class HomeAssistant:
await asyncio.sleep(0)
start_time: float | None = None
current_task = asyncio.current_task()
to_wait: Iterable[asyncio.Future[Any]] = self._tasks
if wait_periodic_tasks:
to_wait = chain(self._tasks, self._periodic_tasks)
while tasks := [
task
for task in to_wait
for task in (
self._tasks | self._periodic_tasks
if wait_periodic_tasks
else self._tasks
)
if task is not current_task and not cancelling(task)
]:
await self._await_and_log_pending(tasks)
@ -980,7 +979,7 @@ class HomeAssistant:
self._tasks = set()
# Cancel all background tasks
for task in chain(self._background_tasks, self._periodic_tasks):
for task in self._background_tasks | self._periodic_tasks:
self._tasks.add(task)
task.add_done_callback(self._tasks.remove)
task.cancel("Home Assistant is stopping")