From b22763f3c6ffe3ccf3363595c4c9a825876118d2 Mon Sep 17 00:00:00 2001 From: Lasse Blaauwbroek Date: Fri, 13 Oct 2023 08:51:51 +0200 Subject: [PATCH] Fix 'AttributeError: '_UnixSelectorEventLoop' object has no attribute 'call_soon' See haata/pycapnp#1 for a discussion. The cause of this bug is still unknown to me. But it likely has been fixed in Python 3.10. For some crazy reason, you can just keep retrying the offending call, and the attribute will magically 'reappear'. --- capnp/lib/capnp.pyx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index dbb92b7..d1a35cb 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -1806,7 +1806,17 @@ cdef cppclass AsyncIoEventPort(EventPort): if runnable: assert this.runHandle is None us = this; - this.runHandle = this.asyncioLoop.call_soon(lambda: kjloop_runnable_callback(us)) + while True: + # TODO: This loop is a workaround for the following occasional nondeterministic bug + # that appears on Python 3.8 and 3.9: + # AttributeError: '_UnixSelectorEventLoop' object has no attribute 'call_soon' + # The cause of this is unknown (either a bug in our code, Cython, or Python). + # It appears to no longer exist in Python 3.10. This can be removed once 3.9 is EOL. + try: + this.runHandle = this.asyncioLoop.call_soon(lambda: kjloop_runnable_callback(us)) + break + except AttributeError: + pass else: assert this.runHandle is not None this.runHandle.cancel()