util.py: run_session() -> async_run()

This commit is contained in:
The MMGen Project 2022-10-17 18:37:23 +00:00
commit c74e15669b
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
21 changed files with 26 additions and 26 deletions

View file

@ -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())

View file

@ -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())

View file

@ -468,4 +468,4 @@ async def main():
elif cmd_args[0] == 'wait':
await do_loop()
run_session(main())
async_run(main())

View file

@ -220,4 +220,4 @@ async def main():
else:
die(1,f'{op!r}: unrecognized operation')
run_session(main())
async_run(main())

View file

@ -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())

View file

@ -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,

View file

@ -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())

View file

@ -98,4 +98,4 @@ async def main():
ask_overwrite = not opt.yes,
ask_write_default_yes = False )
run_session(main())
async_run(main())

View file

@ -151,4 +151,4 @@ async def main():
else:
die(2,'Transaction could not be signed')
run_session(main())
async_run(main())

View file

@ -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())

View file

@ -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())

View file

@ -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())

View file

@ -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)

View file

@ -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:

View file

@ -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)

View file

@ -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:

View file

@ -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()]

View file

@ -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())

View file

@ -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)

View file

@ -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

View file

@ -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