1
0

If util.trigger_callback() is called from the asyncio loop,

run the callback synchronously.
This commit is contained in:
ThomasV
2022-06-03 16:36:02 +02:00
parent a758c99bbe
commit a0e791a6e5

View File

@@ -1619,6 +1619,10 @@ class CallbackManager:
# FIXME: if callback throws, we will lose the traceback
if asyncio.iscoroutinefunction(callback):
asyncio.run_coroutine_threadsafe(callback(event, *args), self.asyncio_loop)
elif get_running_loop() == self.asyncio_loop:
# run callback immediately, so that it is guaranteed
# to have been executed when this method returns
callback(event, *args)
else:
self.asyncio_loop.call_soon_threadsafe(callback, event, *args)