Skip to content

Commit

Permalink
feat: Event name attr and better repr (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Oct 7, 2023
1 parent 07af566 commit f1225fc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion a_sync/primitives/locks/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@

class Event(asyncio.Event, _DebugDaemonMixin):
"""asyncio.Event but with some additional debug logging to help detect deadlocks."""
def __init__(self, debug_daemon_interval: int = 300, *, loop: Optional[asyncio.AbstractEventLoop] = None):
def __init__(self, name: str = "", debug_daemon_interval: int = 300, *, loop: Optional[asyncio.AbstractEventLoop] = None):
if sys.version_info >= (3, 10):
super().__init__()
else:
super().__init__(loop=loop)
self._name = name
self._loop = self._loop or asyncio.get_event_loop()
self._debug_daemon_interval = debug_daemon_interval
def __repr__(self) -> str:
label = f'name={self._name}' if self._name else 'object'
status = 'set' if self._value else 'unset'
if self._waiters:
status += f', waiters:{len(self._waiters)}'
return f"<{self.__class__.__module__}.{self.__class__.__name__} {label} at {hex(id(self))} [{status}]>"
async def wait(self) -> bool:
if self.is_set():
return True
Expand Down

0 comments on commit f1225fc

Please sign in to comment.