diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index d68cc4c..6598f1a 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -489,7 +489,7 @@ class BasicSwap(BaseApp): random.seed(secrets.randbits(128)) def finalise(self): - self.log.info("Finalise") + self.log.info("Finalising") with self.mxDB: self.delay_event.set() @@ -1136,9 +1136,8 @@ class BasicSwap(BaseApp): self.log.error( "No wallets found for coin {}.".format(ci.coin_name()) ) - self.stopRunning( - 1 - ) # systemd will try to restart the process if fail_code != 0 + # systemd will try to restart the process if fail_code != 0 + self.stopRunning(1) startup_tries = self.startup_tries chain_client_settings = self.getChainClientSettings(coin_type) diff --git a/basicswap/bin/prepare.py b/basicswap/bin/prepare.py index c1e85f8..a01f9a1 100755 --- a/basicswap/bin/prepare.py +++ b/basicswap/bin/prepare.py @@ -1990,7 +1990,7 @@ def load_config(config_path): def signal_handler(sig, frame): - logger.info(f"Signal {sig} detected") + os.write(sys.stdout.fileno(), f"Signal {sig} detected.\n".encode("utf-8")) def check_btc_fastsync_data(base_dir, sync_filename): diff --git a/basicswap/bin/run.py b/basicswap/bin/run.py index 5499140..d23c73b 100755 --- a/basicswap/bin/run.py +++ b/basicswap/bin/run.py @@ -6,14 +6,14 @@ # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. -import os -import sys import json +import logging +import os import shutil import signal -import logging -import traceback import subprocess +import sys +import traceback import basicswap.config as cfg from basicswap import __version__ @@ -24,10 +24,11 @@ from basicswap.http_server import HttpThread from basicswap.contrib.websocket_server import WebsocketServer -logger = logging.getLogger() -logger.level = logging.DEBUG -if not len(logger.handlers): - logger.addHandler(logging.StreamHandler(sys.stdout)) +initial_logger = logging.getLogger() +initial_logger.level = logging.DEBUG +if not len(initial_logger.handlers): + initial_logger.addHandler(initial_logger.StreamHandler(sys.stdout)) +logger = initial_logger swap_client = None @@ -48,9 +49,10 @@ def is_known_coin(coin_name: str) -> bool: def signal_handler(sig, frame): - global swap_client - logger.info("Signal %d detected, ending program." % (sig)) - if swap_client is not None: + os.write( + sys.stdout.fileno(), f"Signal {sig} detected, ending program.\n".encode("utf-8") + ) + if swap_client is not None and not swap_client.chainstate_delay_event.is_set(): swap_client.stopRunning() @@ -533,7 +535,7 @@ def runClient(fp, data_dir, chain, start_only_coins): signal.CTRL_C_EVENT if os.name == "nt" else signal.SIGINT ) except Exception as e: - swap_client.log.info("Interrupting %d, error %s", d.handle.pid, str(e)) + swap_client.log.info(f"Interrupting {d.handle.pid}, error {e}") for d in daemons: try: d.handle.wait(timeout=120) @@ -541,8 +543,8 @@ def runClient(fp, data_dir, chain, start_only_coins): if fp: fp.close() closed_pids.append(d.handle.pid) - except Exception as ex: - swap_client.log.error("Error: {}".format(ex)) + except Exception as e: + swap_client.log.error(f"Error: {e}") if os.path.exists(pids_path): with open(pids_path) as fd: diff --git a/basicswap/ui/page_bids.py b/basicswap/ui/page_bids.py index d5fd2d4..9b57d4a 100644 --- a/basicswap/ui/page_bids.py +++ b/basicswap/ui/page_bids.py @@ -149,7 +149,9 @@ def page_bid(self, url_split, post_string): ) -def page_bids(self, url_split, post_string, sent=False, available=False, received=False): +def page_bids( + self, url_split, post_string, sent=False, available=False, received=False +): server = self.server swap_client = server.swap_client swap_client.checkSystemStatus() @@ -220,13 +222,19 @@ def page_bids(self, url_split, post_string, sent=False, available=False, receive "summary": summary, "filter_key": filter_key, "bids": [ - (format_timestamp(b[0]), b[2].hex(), b[3].hex(), - strBidState(b[5]), strTxState(b[7]), - strTxState(b[8]), b[11]) + ( + format_timestamp(b[0]), + b[2].hex(), + b[3].hex(), + strBidState(b[5]), + strTxState(b[7]), + strTxState(b[8]), + b[11], + ) for b in bids ], "bids_count": len(bids), - } + }, ) sent_bids = swap_client.listBids(sent=True, filters=filters)