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'.
This commit is contained in:
Lasse Blaauwbroek 2023-10-13 08:51:51 +02:00 committed by Jacob Alexander
parent ae965128de
commit b22763f3c6

View file

@ -1806,7 +1806,17 @@ cdef cppclass AsyncIoEventPort(EventPort):
if runnable:
assert this.runHandle is None
us = <void*>this;
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()