From 4f591d684e4f4dddde79302a200b98eb82876ee1 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Mon, 16 Dec 2024 05:49:14 -0400 Subject: [PATCH] fix: occasional AttributeError in `CythonEvent.__repr__` (#487) --- a_sync/primitives/locks/event.pyx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/a_sync/primitives/locks/event.pyx b/a_sync/primitives/locks/event.pyx index 142b6f9a..0a216832 100644 --- a/a_sync/primitives/locks/event.pyx +++ b/a_sync/primitives/locks/event.pyx @@ -82,9 +82,18 @@ cdef class CythonEvent(_DebugDaemonMixin): if self.__name else "object" ) + cdef str status = "set" if self._value else "unset" - if self._waiters: - status += ", waiters:{}".format(len(self._waiters)) + + try: + waiters = self._waiters + except AttributeError: + # TODO: debug how this error is possible since _waiters is set in __init__ + pass + else: + if len_waiters := len(waiters): + status += ", waiters:{}".format(len_waiters) + return "<{}.{} {} at {} [{}]>".format( self.__class__.__module__, self.__class__.__name__, @@ -185,4 +194,4 @@ cdef class CythonEvent(_DebugDaemonMixin): cdef inline bint _is_not_done(fut: asyncio.Future): - return fut._state == "PENDING" \ No newline at end of file + return fut._state == "PENDING"