Skip to content

Commit

Permalink
Merge pull request #2326 from opentensor/feat/roman/substrate-definit…
Browse files Browse the repository at this point in the history
…ion-before-initialization

add ConnectionRefusedError raising
  • Loading branch information
roman-opentensor authored Oct 1, 2024
2 parents 27bf3db + e0672f6 commit f13f5f3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def __init__(

self.log_verbose = log_verbose
self._connection_timeout = connection_timeout
self.substrate: "SubstrateInterface" = None
self._get_substrate()

def __str__(self) -> str:
Expand All @@ -201,7 +202,8 @@ def __repr__(self) -> str:

def close(self):
"""Cleans up resources for this subtensor instance like active websocket connection and active extensions."""
self.substrate.close()
if self.substrate:
self.substrate.close()

def _get_substrate(self):
"""Establishes a connection to the Substrate node using configured parameters."""
Expand All @@ -223,14 +225,15 @@ def _get_substrate(self):
except (AttributeError, TypeError, socket.error, OSError) as e:
logging.warning(f"Error setting timeout: {e}")

except ConnectionRefusedError:
except ConnectionRefusedError as error:
logging.error(
f"Could not connect to {self.network} network with {self.chain_endpoint} chain endpoint.",
)
logging.info(
"You can check if you have connectivity by running this command: nc -vz localhost "
f"{self.chain_endpoint.split(':')[2]}"
f"{self.chain_endpoint}"
)
raise ConnectionRefusedError(error.args)

@staticmethod
def config() -> "Config":
Expand Down

0 comments on commit f13f5f3

Please sign in to comment.