diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index 5296ba419..77fa1ddc0 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -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: @@ -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.""" @@ -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":