From a0e791a6e5fd6b225b7e2678c3e90d025e490b92 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 3 Jun 2022 16:36:02 +0200 Subject: [PATCH] If util.trigger_callback() is called from the asyncio loop, run the callback synchronously. --- electrum/util.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/electrum/util.py b/electrum/util.py index 22835f5cd..c9f22ff50 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -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)