Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import asyncio
import curses
import importlib
import os.path
import re
import ssl
Expand Down Expand Up @@ -504,6 +505,7 @@ class CLIManager:
subnets_app: typer.Typer
weights_app: typer.Typer
utils_app = typer.Typer(epilog=_epilog)
asyncio_runner = asyncio

def __init__(self):
self.config = {
Expand Down Expand Up @@ -937,15 +939,12 @@ async def _run():
try:
raise typer.Exit()
except Exception as e: # ensures we always exit cleanly
if not isinstance(e, (typer.Exit, RuntimeError)): # temporarily to handle multiple run commands in one session
if not isinstance(
e, (typer.Exit, RuntimeError)
): # temporarily to handle multiple run commands in one session
err_console.print(f"An unknown error has occurred: {e}")

if sys.version_info < (3, 10):
# For Python 3.9 or lower
return asyncio.get_event_loop().run_until_complete(_run())
else:
# For Python 3.10 or higher
return asyncio.run(_run())
return self.asyncio_runner(_run())

def main_callback(
self,
Expand Down Expand Up @@ -996,6 +995,20 @@ def main_callback(
if k in self.config.keys():
self.config[k] = v

if sys.version_info < (3, 10):
# For Python 3.9 or lower
self.asyncio_runner = asyncio.get_event_loop().run_until_complete
else:
try:
uvloop = importlib.import_module("uvloop")
if sys.version_info >= (3, 11):
self.asyncio_runner = uvloop.run
else:
uvloop.install()
self.asyncio_runner = asyncio.run
except ModuleNotFoundError:
self.asyncio_runner = asyncio

def verbosity_handler(self, quiet: bool, verbose: bool):
if quiet and verbose:
err_console.print("Cannot specify both `--quiet` and `--verbose`")
Expand Down