From 347a4a4077d92969f16d59e2f0fcd81470d90d46 Mon Sep 17 00:00:00 2001 From: zebra-lucky Date: Sat, 29 Nov 2025 19:52:30 +0200 Subject: [PATCH] fix BitcoinCoreInterface._rpc, twisted_sys_exit, finalize_main_task --- src/jmbase/support.py | 6 +++--- src/jmclient/blockchaininterface.py | 2 +- src/jmclient/scripts_support.py | 12 ++++-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/jmbase/support.py b/src/jmbase/support.py index 6f341f2..9ed8cb7 100644 --- a/src/jmbase/support.py +++ b/src/jmbase/support.py @@ -11,6 +11,7 @@ from sqlite3 import Cursor, Row from typing import Callable, List, Optional import urllib.parse as urlparse + # JoinMarket version JM_CORE_VERSION = '0.9.12dev' @@ -25,9 +26,8 @@ EXIT_ARGERROR = 2 def twisted_sys_exit(status): - from twisted.internet import reactor - if reactor.running: - reactor.stop() + from .twisted_utils import stop_reactor + stop_reactor() sys.exit(status) diff --git a/src/jmclient/blockchaininterface.py b/src/jmclient/blockchaininterface.py index caccee9..5b90c18 100644 --- a/src/jmclient/blockchaininterface.py +++ b/src/jmclient/blockchaininterface.py @@ -442,7 +442,7 @@ class BitcoinCoreInterface(BlockchainInterface): log.error("Failure of RPC connection to Bitcoin Core. " "Application cannot continue, shutting down.") stop_reactor() - return None + twisted_sys_exit(EXIT_FAILURE) # note that JsonRpcError is not caught here; for some calls, we # have specific behaviour requirements depending on these errors, # so this is handled elsewhere in BitcoinCoreInterface. diff --git a/src/jmclient/scripts_support.py b/src/jmclient/scripts_support.py index a62de88..5fff263 100644 --- a/src/jmclient/scripts_support.py +++ b/src/jmclient/scripts_support.py @@ -6,7 +6,7 @@ from functools import wraps from twisted.internet import reactor -from jmbase import jmprint +from jmbase import jmprint, stop_reactor def wrap_main(func): @@ -18,13 +18,9 @@ def wrap_main(func): except SystemExit as e: return e.args[0] if e.args else None finally: - try: - for task in asyncio.all_tasks(): - task.cancel() - if reactor.running: - reactor.stop() - except Exception as e: - jmprint(f'Errors during reactor cleaenup/stop: {e}', 'debug') + for task in asyncio.all_tasks(): + task.cancel() + stop_reactor() return func_wrapper