diff --git a/a_sync/primitives/locks/event.py b/a_sync/primitives/locks/event.py index e3d8b88b..01b74719 100644 --- a/a_sync/primitives/locks/event.py +++ b/a_sync/primitives/locks/event.py @@ -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