From e87cbe2f5c7e0503042442ab58d866faa81b5610 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:53:48 -0400 Subject: [PATCH] chore: cleanup repr (#76) --- a_sync/primitives/locks/prio_semaphore.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/a_sync/primitives/locks/prio_semaphore.py b/a_sync/primitives/locks/prio_semaphore.py index e10d247c..33fab2fc 100644 --- a/a_sync/primitives/locks/prio_semaphore.py +++ b/a_sync/primitives/locks/prio_semaphore.py @@ -44,7 +44,7 @@ def __init__(self, value: int = 1, *, name: Optional[str] = None) -> None: self._potential_lost_waiters = [] def __repr__(self) -> str: - return f"<{self.__class__.__name__} name={self.name} capacity={self._capacity} value={self._value} waiters={[manager._repr_no_parent_() for manager in self._waiters]}>" + return f"<{self.__class__.__name__} name={self.name} capacity={self._capacity} value={self._value} waiters={self._count_waiters()}>" async def __aenter__(self) -> None: await self[self._top_priority].acquire() @@ -72,6 +72,9 @@ def locked(self) -> bool: ) ) + def _count_waiters(self) -> Dict[PT, int]: + return {manager._priority: len(manager._waiters) for manager in sorted(self._waiters, key=lambda m: m._priority)} + def _wake_up_next(self) -> None: while self._waiters: manager = heapq.heappop(self._waiters)