Freeze global timeout when installing packages

fixes #119023
This commit is contained in:
J. Nick Koston 2024-06-08 01:54:17 -05:00
parent e4be3d8435
commit 064659fce1
No known key found for this signature in database
2 changed files with 8 additions and 5 deletions

View File

@ -276,7 +276,9 @@ class RequirementsManager:
async with self.pip_lock:
# Recalculate missing again now that we have the lock
if missing := self._find_missing_requirements(requirements):
await self._async_process_requirements(name, missing)
# Freeze all the timers since installing packages can take a long time
async with self.hass.timeout.async_freeze():
await self._async_process_requirements(name, missing)
def _find_missing_requirements(self, requirements: list[str]) -> list[str]:
"""Find requirements that are missing in the cache."""

View File

@ -74,11 +74,12 @@ class _GlobalFreezeContext:
continue
zone.pause()
self._manager.global_freezes.append(self)
self._manager.global_freezes.add(self)
def _exit(self) -> None:
"""Finish freeze."""
self._manager.global_freezes.remove(self)
self._manager.global_freezes.discard(self)
if not self._manager.freezes_done:
return
@ -423,7 +424,7 @@ class TimeoutManager:
self._loop: asyncio.AbstractEventLoop = asyncio.get_running_loop()
self._zones: dict[str, _ZoneTimeoutManager] = {}
self._globals: list[_GlobalTaskContext] = []
self._freezes: list[_GlobalFreezeContext] = []
self._freezes: set[_GlobalFreezeContext] = set()
@property
def zones_done(self) -> bool:
@ -446,7 +447,7 @@ class TimeoutManager:
return self._globals
@property
def global_freezes(self) -> list[_GlobalFreezeContext]:
def global_freezes(self) -> set[_GlobalFreezeContext]:
"""Return all global Freezes."""
return self._freezes