diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index 2c8fb4e84..fc1a6a738 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Optional, Dict, Union, Sequence, Tuple, Iterab from decimal import Decimal import math import time +import concurrent.futures import attr import aiohttp @@ -952,12 +953,19 @@ class SwapManager(Logger): self.trigger_pairs_updated_threadsafe() def trigger_pairs_updated_threadsafe(self): + future = concurrent.futures.Future() def trigger(): self.is_initialized.set() self.pairs_updated.set() self.pairs_updated.clear() - loop = get_asyncio_loop() - loop.call_soon_threadsafe(trigger) + future.set_result(None) + asyncio_loop = get_asyncio_loop() + if get_running_loop() == asyncio_loop: + trigger() # this is running on the asyncio event loop + else: + asyncio_loop.call_soon_threadsafe(trigger) + # block until the event loop has run the trigger function + _ = future.result() def server_maybe_trigger_liquidity_update(self) -> None: """