Skip to content

Commit 73558cf

Browse files
authored
Merge pull request #463 from opentensor/feat/thewhaleking/suppress-async-substrate-warning
2 parents 61bd3bf + 91601f7 commit 73558cf

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

bittensor_cli/cli.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ssl
99
import sys
1010
import traceback
11+
import warnings
1112
from pathlib import Path
1213
from typing import Coroutine, Optional
1314
from dataclasses import fields
@@ -1000,31 +1001,37 @@ def initialize_chain(
10001001
:param network: Network name (e.g. finney, test, etc.) or
10011002
chain endpoint (e.g. ws://127.0.0.1:9945, wss://entrypoint-finney.opentensor.ai:443)
10021003
"""
1003-
if not self.subtensor:
1004-
if network:
1005-
network_ = None
1006-
for item in network:
1007-
if item.startswith("ws"):
1008-
network_ = item
1009-
break
1010-
else:
1011-
network_ = item
1004+
with warnings.catch_warnings():
1005+
warnings.filterwarnings(
1006+
"ignore",
1007+
"You are instantiating the AsyncSubstrateInterface Websocket outside of an event loop. "
1008+
"Verify this is intended.",
1009+
)
1010+
if not self.subtensor:
1011+
if network:
1012+
network_ = None
1013+
for item in network:
1014+
if item.startswith("ws"):
1015+
network_ = item
1016+
break
1017+
else:
1018+
network_ = item
1019+
1020+
not_selected_networks = [net for net in network if net != network_]
1021+
if not_selected_networks:
1022+
console.print(
1023+
f"Networks not selected: [dark_orange]{', '.join(not_selected_networks)}[/dark_orange]"
1024+
)
10121025

1013-
not_selected_networks = [net for net in network if net != network_]
1014-
if not_selected_networks:
1026+
self.subtensor = SubtensorInterface(network_)
1027+
elif self.config["network"]:
1028+
self.subtensor = SubtensorInterface(self.config["network"])
10151029
console.print(
1016-
f"Networks not selected: [dark_orange]{', '.join(not_selected_networks)}[/dark_orange]"
1030+
f"Using the specified network [{COLORS.G.LINKS}]{self.config['network']}"
1031+
f"[/{COLORS.G.LINKS}] from config"
10171032
)
1018-
1019-
self.subtensor = SubtensorInterface(network_)
1020-
elif self.config["network"]:
1021-
self.subtensor = SubtensorInterface(self.config["network"])
1022-
console.print(
1023-
f"Using the specified network [{COLORS.G.LINKS}]{self.config['network']}"
1024-
f"[/{COLORS.G.LINKS}] from config"
1025-
)
1026-
else:
1027-
self.subtensor = SubtensorInterface(defaults.subtensor.network)
1033+
else:
1034+
self.subtensor = SubtensorInterface(defaults.subtensor.network)
10281035
return self.subtensor
10291036

10301037
def _run_command(self, cmd: Coroutine, exit_early: bool = True):

0 commit comments

Comments
 (0)