@@ -643,6 +643,17 @@ def __init__(self):
643
643
# },
644
644
}
645
645
self .subtensor = None
646
+
647
+ if sys .version_info < (3 , 10 ):
648
+ # For Python 3.9 or lower
649
+ self .event_loop = asyncio .new_event_loop ()
650
+ else :
651
+ try :
652
+ uvloop = importlib .import_module ("uvloop" )
653
+ self .event_loop = uvloop .new_event_loop ()
654
+ except ModuleNotFoundError :
655
+ self .event_loop = asyncio .new_event_loop ()
656
+
646
657
self .config_base_path = os .path .expanduser (defaults .config .base_path )
647
658
self .config_path = os .path .expanduser (defaults .config .path )
648
659
@@ -1097,12 +1108,9 @@ async def _run():
1097
1108
initiated = False
1098
1109
try :
1099
1110
if self .subtensor :
1100
- async with self .subtensor :
1101
- initiated = True
1102
- result = await cmd
1103
- else :
1104
- initiated = True
1105
- result = await cmd
1111
+ await self .subtensor .substrate .initialize ()
1112
+ initiated = True
1113
+ result = await cmd
1106
1114
return result
1107
1115
except (ConnectionRefusedError , ssl .SSLError , InvalidHandshake ):
1108
1116
err_console .print (f"Unable to connect to the chain: { self .subtensor } " )
@@ -1128,12 +1136,13 @@ async def _run():
1128
1136
exit_early is True
1129
1137
): # temporarily to handle multiple run commands in one session
1130
1138
try :
1139
+ await self .subtensor .substrate .close ()
1131
1140
raise typer .Exit ()
1132
1141
except Exception as e : # ensures we always exit cleanly
1133
1142
if not isinstance (e , (typer .Exit , RuntimeError )):
1134
1143
err_console .print (f"An unknown error has occurred: { e } " )
1135
1144
1136
- return self .asyncio_runner (_run ())
1145
+ return self .event_loop . run_until_complete (_run ())
1137
1146
1138
1147
def main_callback (
1139
1148
self ,
@@ -1184,20 +1193,6 @@ def main_callback(
1184
1193
if k in self .config .keys ():
1185
1194
self .config [k ] = v
1186
1195
1187
- if sys .version_info < (3 , 10 ):
1188
- # For Python 3.9 or lower
1189
- self .asyncio_runner = asyncio .get_event_loop ().run_until_complete
1190
- else :
1191
- try :
1192
- uvloop = importlib .import_module ("uvloop" )
1193
- if sys .version_info >= (3 , 11 ):
1194
- self .asyncio_runner = uvloop .run
1195
- else :
1196
- uvloop .install ()
1197
- self .asyncio_runner = asyncio .run
1198
- except ModuleNotFoundError :
1199
- self .asyncio_runner = asyncio .run
1200
-
1201
1196
def verbosity_handler (
1202
1197
self , quiet : bool , verbose : bool , json_output : bool = False
1203
1198
) -> None :
0 commit comments