From c74e15669b175eeb96ac2e4c710abb394d62b240 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 17 Oct 2022 18:37:23 +0000 Subject: [PATCH] util.py: run_session() -> async_run() --- examples/halving-calculator.py | 2 +- mmgen/main_addrimport.py | 2 +- mmgen/main_autosign.py | 2 +- mmgen/main_msg.py | 2 +- mmgen/main_regtest.py | 2 +- mmgen/main_tool.py | 2 +- mmgen/main_txbump.py | 2 +- mmgen/main_txcreate.py | 2 +- mmgen/main_txdo.py | 2 +- mmgen/main_txsend.py | 2 +- mmgen/main_txsign.py | 2 +- mmgen/main_xmrwallet.py | 4 ++-- mmgen/util.py | 2 +- mmgen/xmrwallet.py | 2 +- test/include/coin_daemon_control.py | 2 +- test/test.py | 4 ++-- test/test_py_d/ts_main.py | 2 +- test/test_py_d/ts_xmrwallet.py | 4 ++-- test/tooltest2.py | 2 +- test/unit_tests.py | 2 +- test/unit_tests_d/ut_rpc.py | 6 +++--- 21 files changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/halving-calculator.py b/examples/halving-calculator.py index 0d2c6be2..4bff7ab0 100755 --- a/examples/halving-calculator.py +++ b/examples/halving-calculator.py @@ -76,4 +76,4 @@ async def main(): f'Est. time until halving: {dhms(cur["time"] + t_rem - clock_time)}\n' ) -run_session(main()) +async_run(main()) diff --git a/mmgen/main_addrimport.py b/mmgen/main_addrimport.py index ebfe069c..79a372f0 100755 --- a/mmgen/main_addrimport.py +++ b/mmgen/main_addrimport.py @@ -184,4 +184,4 @@ cmd_args = opts.init(opts_data) from .protocol import init_proto_from_opts proto = init_proto_from_opts() import asyncio -run_session(main()) +async_run(main()) diff --git a/mmgen/main_autosign.py b/mmgen/main_autosign.py index e8cf0144..f02bd919 100755 --- a/mmgen/main_autosign.py +++ b/mmgen/main_autosign.py @@ -468,4 +468,4 @@ async def main(): elif cmd_args[0] == 'wait': await do_loop() -run_session(main()) +async_run(main()) diff --git a/mmgen/main_msg.py b/mmgen/main_msg.py index 807309dd..6385e751 100755 --- a/mmgen/main_msg.py +++ b/mmgen/main_msg.py @@ -220,4 +220,4 @@ async def main(): else: die(1,f'{op!r}: unrecognized operation') -run_session(main()) +async_run(main()) diff --git a/mmgen/main_regtest.py b/mmgen/main_regtest.py index 49d1b86f..8ca67265 100755 --- a/mmgen/main_regtest.py +++ b/mmgen/main_regtest.py @@ -82,4 +82,4 @@ elif cmd_args[0] not in ('cli','wallet_cli','balances'): async def main(): await MMGenRegtest(g.coin).cmd(cmd_args) -run_session(main()) +async_run(main()) diff --git a/mmgen/main_tool.py b/mmgen/main_tool.py index f79e7fc7..058364ae 100755 --- a/mmgen/main_tool.py +++ b/mmgen/main_tool.py @@ -379,7 +379,7 @@ if g.prog_name == 'mmgen-tool' and not opt._lock: ret = getattr(cls(cmdname=cmd),cmd)(*args,**kwargs) if type(ret).__name__ == 'coroutine': - ret = run_session(ret) + ret = async_run(ret) process_result( ret, diff --git a/mmgen/main_txbump.py b/mmgen/main_txbump.py index 8b648cae..f944a650 100755 --- a/mmgen/main_txbump.py +++ b/mmgen/main_txbump.py @@ -181,4 +181,4 @@ async def main(): else: tx.file.write(ask_write=not opt.yes,ask_write_default_yes=False,ask_overwrite=not opt.yes) -run_session(main()) +async_run(main()) diff --git a/mmgen/main_txcreate.py b/mmgen/main_txcreate.py index bf6fa02a..9bc143ea 100755 --- a/mmgen/main_txcreate.py +++ b/mmgen/main_txcreate.py @@ -98,4 +98,4 @@ async def main(): ask_overwrite = not opt.yes, ask_write_default_yes = False ) -run_session(main()) +async_run(main()) diff --git a/mmgen/main_txdo.py b/mmgen/main_txdo.py index 867e71c1..eaba4375 100755 --- a/mmgen/main_txdo.py +++ b/mmgen/main_txdo.py @@ -151,4 +151,4 @@ async def main(): else: die(2,'Transaction could not be signed') -run_session(main()) +async_run(main()) diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index 471fe733..e378d644 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -79,4 +79,4 @@ async def main(): tx.file.write(ask_overwrite=False,ask_write=False) tx.print_contract_addr() -run_session(main()) +async_run(main()) diff --git a/mmgen/main_txsign.py b/mmgen/main_txsign.py index 16694ced..ddcdcca6 100755 --- a/mmgen/main_txsign.py +++ b/mmgen/main_txsign.py @@ -160,4 +160,4 @@ async def main(): if bad_tx_count: die(2,f'{bad_tx_count} transaction{suf(bad_tx_count)} could not be signed') -run_session(main()) +async_run(main()) diff --git a/mmgen/main_xmrwallet.py b/mmgen/main_xmrwallet.py index ab0996ee..cfc827bf 100755 --- a/mmgen/main_xmrwallet.py +++ b/mmgen/main_xmrwallet.py @@ -263,9 +263,9 @@ uopts = uo( m = getattr(MoneroWalletOps,op)(uargs,uopts) try: - if run_session(m.main()): + if async_run(m.main()): m.post_main() except KeyboardInterrupt: ymsg('\nUser interrupt') finally: - run_session(m.stop_wallet_daemon()) + async_run(m.stop_wallet_daemon()) diff --git a/mmgen/util.py b/mmgen/util.py index 550aa122..60d599ed 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -383,7 +383,7 @@ def get_subclasses(cls,names=False): yield j return tuple((c.__name__ for c in gen(cls)) if names else gen(cls)) -def run_session(coro): +def async_run(coro): import asyncio return asyncio.run(coro) diff --git a/mmgen/xmrwallet.py b/mmgen/xmrwallet.py index 4fd770ef..56cd2f4e 100755 --- a/mmgen/xmrwallet.py +++ b/mmgen/xmrwallet.py @@ -372,7 +372,7 @@ class MoneroWalletOps: self.c = MoneroWalletRPCClient(daemon=self.wd,test_connection=False) if not uopt.no_start_wallet_daemon: - run_session(self.c.restart_daemon()) + async_run(self.c.restart_daemon()) def create_addr_data(self): if uarg.wallets: diff --git a/test/include/coin_daemon_control.py b/test/include/coin_daemon_control.py index 23a26186..a698656c 100755 --- a/test/include/coin_daemon_control.py +++ b/test/include/coin_daemon_control.py @@ -78,7 +78,7 @@ def run(network_id=None,proto=None,daemon_id=None,missing_exec_ok=True): print(' '.join(cmd)) else: if action == 'stop' and hasattr(d,'rpc'): - run_session(d.rpc.stop_daemon(quiet=opt.quiet)) + async_run(d.rpc.stop_daemon(quiet=opt.quiet)) else: d.cmd(action,quiet=opt.quiet) diff --git a/test/test.py b/test/test.py index d4ded03e..1e02240a 100755 --- a/test/test.py +++ b/test/test.py @@ -729,7 +729,7 @@ class TestSuiteRunner(object): if isinstance(e,KeyError) and e.args[0] == cmdname: ret = getattr(self.ts,cmdname)() if type(ret).__name__ == 'coroutine': - run_session(ret) + async_run(ret) else: raise do_between() @@ -850,7 +850,7 @@ class TestSuiteRunner(object): ret = getattr(self.ts,cmd)(*arg_list) # run the test if type(ret).__name__ == 'coroutine': - ret = run_session(ret) + ret = async_run(ret) self.process_retval(cmd,ret) if opt.profile: diff --git a/test/test_py_d/ts_main.py b/test/test_py_d/ts_main.py index 67746498..ad48378f 100755 --- a/test/test_py_d/ts_main.py +++ b/test/test_py_d/ts_main.py @@ -194,7 +194,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared): TestSuiteBase.__init__(self,trunner,cfgs,spawn) if trunner == None or self.proto.coin.lower() not in self.networks: return - self.rpc = run_session(rpc_init(self.proto)) + self.rpc = async_run(rpc_init(self.proto)) self.lbl_id = ('account','label')['label_api' in self.rpc.caps] if self.proto.coin in ('BTC','BCH','LTC'): self.tx_fee = {'btc':'0.0001','bch':'0.001','ltc':'0.01'}[self.proto.coin.lower()] diff --git a/test/test_py_d/ts_xmrwallet.py b/test/test_py_d/ts_xmrwallet.py index 780d01cd..8bfb7380 100755 --- a/test/test_py_d/ts_xmrwallet.py +++ b/test/test_py_d/ts_xmrwallet.py @@ -707,7 +707,7 @@ class TestSuiteXMRWallet(TestSuiteBase): def stop_daemons(self): for v in self.users.values(): - run_session(v.md_rpc.stop_daemon()) + async_run(v.md_rpc.stop_daemon()) def stop_miner_wallet_daemon(self): - run_session(self.users['miner'].wd_rpc.stop_daemon()) + async_run(self.users['miner'].wd_rpc.stop_daemon()) diff --git a/test/tooltest2.py b/test/tooltest2.py index c1fd15b6..1098be57 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -999,6 +999,6 @@ async def main(): except KeyboardInterrupt: die(1,green('\nExiting at user request')) -run_session(main()) +async_run(main()) end_msg(int(time.time()) - start_time) diff --git a/test/unit_tests.py b/test/unit_tests.py index 4ac11e1e..cea3de3c 100755 --- a/test/unit_tests.py +++ b/test/unit_tests.py @@ -112,7 +112,7 @@ def run_test(test,subtest=None): t = getattr(mod,'unit_tests')() ret = getattr(t,subtest.replace('-','_'))(test,UnitTestHelpers) if type(ret).__name__ == 'coroutine': - ret = run_session(ret) + ret = async_run(ret) if not ret: die(4,f'Unit subtest {subtest_disp!r} failed') pass diff --git a/test/unit_tests_d/ut_rpc.py b/test/unit_tests_d/ut_rpc.py index 308ead72..91582a84 100755 --- a/test/unit_tests_d/ut_rpc.py +++ b/test/unit_tests_d/ut_rpc.py @@ -27,7 +27,7 @@ def cfg_file_auth_test(proto,d): rpc = await rpc_init(proto) assert rpc.auth.user == 'ut_rpc', f'{rpc.auth.user}: user is not ut_rpc!' - run_session(do()) + async_run(do()) d.stop() def print_daemon_info(rpc): @@ -96,7 +96,7 @@ def run_test(network_ids,test_cf_auth=False,daemon_ids=None): for n,backend in enumerate(g.autoset_opts['rpc_backend'].choices): test = getattr(init_test,d.proto.coin.lower()) - rpc = run_session(test(d.proto,backend,d)) + rpc = async_run(test(d.proto,backend,d)) if not n and opt.verbose: print_daemon_info(rpc) @@ -209,5 +209,5 @@ class unit_tests: import shutil shutil.rmtree('test/trash2',ignore_errors=True) os.makedirs('test/trash2') - run_session(run()) + async_run(run()) return True