diff --git a/electrum/scripts/bip39_recovery.py b/electrum/scripts/bip39_recovery.py index da51d890f..f819bc87a 100755 --- a/electrum/scripts/bip39_recovery.py +++ b/electrum/scripts/bip39_recovery.py @@ -38,3 +38,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/block_headers.py b/electrum/scripts/block_headers.py index aac821032..de3617390 100755 --- a/electrum/scripts/block_headers.py +++ b/electrum/scripts/block_headers.py @@ -36,3 +36,5 @@ async def f(): # 2. send the subscription asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/estimate_fee.py b/electrum/scripts/estimate_fee.py index a281a65bc..c710250a3 100755 --- a/electrum/scripts/estimate_fee.py +++ b/electrum/scripts/estimate_fee.py @@ -28,3 +28,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/get_history.py b/electrum/scripts/get_history.py index cff747802..ded6685dc 100755 --- a/electrum/scripts/get_history.py +++ b/electrum/scripts/get_history.py @@ -31,3 +31,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/ln_features.py b/electrum/scripts/ln_features.py index fd93bb51a..954fdbc56 100644 --- a/electrum/scripts/ln_features.py +++ b/electrum/scripts/ln_features.py @@ -8,6 +8,9 @@ https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md import asyncio import os import time +from typing import Optional + +from aiorpcx import NetAddress from electrum.logging import get_logger, configure_logging from electrum.simple_config import SimpleConfig @@ -52,7 +55,6 @@ if not os.path.exists(wallet_path): # open wallet wallet = daemon.load_wallet(wallet_path, password=None, upgrade=True) -wallet.start_network(network) async def worker(work_queue: asyncio.Queue, results_queue: asyncio.Queue, flag): @@ -67,19 +69,15 @@ async def worker(work_queue: asyncio.Queue, results_queue: asyncio.Queue, flag): work = await work_queue.get() # only check non-onion addresses - addr = None - for a in work['addrs']: - if "onion" not in a[0]: + addr = None # type: Optional[NetAddress] + for a in work['addrs']: # type: NetAddress + if not str(a.host).endswith(".onion"): addr = a if not addr: await results_queue.put(None) continue - # handle ipv4/ipv6 - if ':' in addr[0]: - connect_str = f"{work['pk'].hex()}@[{addr.host}]:{addr.port}" - else: - connect_str = f"{work['pk'].hex()}@{addr.host}:{addr.port}" + connect_str = f"{work['pk'].hex()}@{addr}" print(f"worker connecting to {connect_str}") try: @@ -177,3 +175,5 @@ async def node_flag_stats(opt_flag: LnFeatures, presync: False): asyncio.run_coroutine_threadsafe( node_flag_stats(FLAG, presync=PRESYNC), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/peers.py b/electrum/scripts/peers.py index 0a65edf2d..1cc3ad07a 100755 --- a/electrum/scripts/peers.py +++ b/electrum/scripts/peers.py @@ -27,3 +27,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/servers.py b/electrum/scripts/servers.py index e3023d1e4..26d479e9c 100755 --- a/electrum/scripts/servers.py +++ b/electrum/scripts/servers.py @@ -25,3 +25,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/txbroadcast.py b/electrum/scripts/txbroadcast.py index 6cde24d27..78db77bad 100644 --- a/electrum/scripts/txbroadcast.py +++ b/electrum/scripts/txbroadcast.py @@ -34,3 +34,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/txradar.py b/electrum/scripts/txradar.py index c220733e7..9f0adc9ba 100755 --- a/electrum/scripts/txradar.py +++ b/electrum/scripts/txradar.py @@ -36,3 +36,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/update_default_servers.py b/electrum/scripts/update_default_servers.py index 76b6ee17f..2f4bacfd0 100755 --- a/electrum/scripts/update_default_servers.py +++ b/electrum/scripts/update_default_servers.py @@ -61,3 +61,5 @@ async def f(): stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop) +while loop_thread.is_alive(): + loop_thread.join(1) diff --git a/electrum/scripts/watch_address.py b/electrum/scripts/watch_address.py index 297ec2ea2..01c404922 100755 --- a/electrum/scripts/watch_address.py +++ b/electrum/scripts/watch_address.py @@ -18,7 +18,7 @@ except Exception: config = SimpleConfig() # start network -loop = create_and_start_event_loop()[0] +loop, stopping_fut, loop_thread = create_and_start_event_loop() network = Network(config) network.start() @@ -45,3 +45,5 @@ class Notifier(SynchronizerBase): notifier = Notifier(network) asyncio.run_coroutine_threadsafe(notifier.watch_queue.put(addr), loop) +while loop_thread.is_alive(): + loop_thread.join(1)