Skip to content

Commit

Permalink
fix: temporary hacky-fix to prevent issues in downstream libs (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Nov 22, 2024
1 parent 4fc7c9d commit 17da9c4
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions a_sync/primitives/locks/prio_semaphore.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
# NOTE: This should (hopefully) be temporary
self._potential_lost_waiters: List["asyncio.Future[None]"] = []
"""A list of futures representing waiters that might have been lost."""

def __init__(self, value: int = 1, *, name: Optional[str] = None) -> None:

def __init__(
self,
context_manager_class: Type[_AbstractPrioritySemaphoreContextManager],
top_priority: object,
value: int = 1,
*,
name: Optional[str] = None,
) -> None:
"""Initializes the priority semaphore.

Args:
Expand All @@ -61,11 +68,15 @@ cdef class _AbstractPrioritySemaphore(Semaphore):
Examples:
>>> semaphore = _AbstractPrioritySemaphore(5, name="test_semaphore")
"""
# context manager class is some temporary hacky shit, just ignore this
super().__init__(value, name=name)

self._capacity = value
"""The initial capacity of the semaphore."""

self._top_priority = top_priority
self._context_manager_class = context_manager_class

def __repr__(self) -> str:
"""Returns a string representation of the semaphore."""
return f"<{self.__class__.__name__} name={self.name} capacity={self._capacity} value={self._Semaphore__value} waiters={self._count_waiters()}>"
Expand Down Expand Up @@ -431,10 +442,7 @@ cdef class PrioritySemaphore(_AbstractPrioritySemaphore): # type: ignore [type-
:class:`_AbstractPrioritySemaphore` for the base class implementation.
"""

def __cinit__(self):
self._top_priority = -1
self._context_manager_class = _PrioritySemaphoreContextManager

def __cinit__(self):
# _AbstractPrioritySemaphore.__cinit__(self)

self._context_managers = {}
Expand All @@ -446,6 +454,15 @@ cdef class PrioritySemaphore(_AbstractPrioritySemaphore): # type: ignore [type-
# NOTE: This should (hopefully) be temporary
self._potential_lost_waiters: List["asyncio.Future[None]"] = []
"""A list of futures representing waiters that might have been lost."""

def __init__(
self,
value: int = 1,
*,
name: Optional[str] = None,
) -> None:
# context manager class is some temporary hacky shit, just ignore this
super().__init__(_PrioritySemaphoreContextManager, -1, value, name=name)

def __getitem__(
self, priority: Optional[PT]
Expand Down

0 comments on commit 17da9c4

Please sign in to comment.