From ad41927179fe51ba845226d81f8402a2a5d48900 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 1 May 2023 14:39:19 +0000 Subject: [PATCH] xmrwallet.py: register with atexit to stop wallet daemon --- mmgen/main_xmrwallet.py | 5 ----- mmgen/xmrwallet.py | 14 ++++++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index 153945de..01bfff39 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -166,10 +166,5 @@ try: except KeyboardInterrupt: ymsg('\nUser interrupt') -try: - async_run(m.stop_wallet_daemon()) -except Exception as e: - ymsg(f'Unable to stop wallet daemon: {type(e).__name__}: {e}') - if m.do_umount and cfg.autosign and not cfg.test_suite: asi.do_umount() diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 31f4c3b0..a10bf113 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -20,7 +20,7 @@ xmrwallet.py - MoneroWalletOps class """ -import re,time,json +import re,time,json,atexit from collections import namedtuple from pathlib import PosixPath as Path @@ -816,7 +816,7 @@ class MoneroWalletOps: ) if self.start_daemon and not self.cfg.no_start_wallet_daemon: - async_run(self.c.restart_daemon()) + async_run(self.restart_wallet_daemon()) @classmethod def get_idx_from_fn(cls,fn): @@ -861,6 +861,10 @@ class MoneroWalletOps: else: self.addr_data = self.kal.data + async def restart_wallet_daemon(self): + atexit.register(lambda: async_run(self.stop_wallet_daemon())) + await self.c.restart_daemon() + async def stop_wallet_daemon(self): if not self.cfg.no_stop_wallet_daemon: await self.c.stop_daemon() @@ -1623,7 +1627,7 @@ class MoneroWalletOps: offline = True async def main(self,fn): - await self.c.restart_daemon() + await self.restart_wallet_daemon() tx = MoneroMMGenTX.Unsigned( self.cfg, fn ) h = self.rpc(self,self.addr_data[0]) self.head_msg(tx.src_wallet_idx,h.fn) @@ -1641,7 +1645,6 @@ class MoneroWalletOps: signed_txset = res['signed_txset'], _in_tx = tx, ) - await self.stop_wallet_daemon() return new_tx class submit(wallet): @@ -1738,7 +1741,7 @@ class MoneroWalletOps: offline = True async def main(self,fn,wallet_idx): - await self.c.restart_daemon() + await self.restart_wallet_daemon() h = self.rpc(self,self.addr_data[0]) self.head_msg(wallet_idx,fn) h.open_wallet() @@ -1758,7 +1761,6 @@ class MoneroWalletOps: data = data ) idata = m.data.signed_key_images or [] bmsg(' {} key image{} signed'.format( len(idata), suf(idata) )) - await self.stop_wallet_daemon() return m class import_key_images(wallet):