diff --git a/homeassistant/requirements.py b/homeassistant/requirements.py index c0e92610b6e..e17f5c1d2ba 100644 --- a/homeassistant/requirements.py +++ b/homeassistant/requirements.py @@ -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.""" diff --git a/homeassistant/util/timeout.py b/homeassistant/util/timeout.py index 72cabffeed6..36434688988 100644 --- a/homeassistant/util/timeout.py +++ b/homeassistant/util/timeout.py @@ -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