Skip to content

Commit

Permalink
chore: cleanup repr (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Oct 5, 2023
1 parent bd528e5 commit e87cbe2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion a_sync/primitives/locks/prio_semaphore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e87cbe2

Please sign in to comment.