Exemple #1
0
    def ensure_connection(self, config):
        if self._connection:
            return self._connection

        _100_MB = 100 * 1024 * 1024
        server_config = config
        host, port = server_config.address.split(":")
        addr = socket.gethostbyname(host)
        logger.debug("Trying to connect to tiktorch server using %s(%s):%s", host, addr, port),
        self._chan = grpc.insecure_channel(
            f"{addr}:{port}",
            options=[("grpc.max_send_message_length", _100_MB), ("grpc.max_receive_message_length", _100_MB)],
        )
        client = inference_pb2_grpc.InferenceStub(self._chan)
        upload_client = data_store_pb2_grpc.DataStoreStub(self._chan)
        self._devices = [d.id for d in server_config.devices if d.enabled]
        self._connection = Connection(client, upload_client)
        return self._connection
Exemple #2
0
    def ensure_connection(self, config):
        if self._connection:
            return self._connection

        _100_MB = 100 * 1024 * 1024
        server_config = config
        addr, port = socket.gethostbyname(
            server_config.address), server_config.port
        conn_conf = ConnConf(addr, port, timeout=20)

        if server_config.autostart:
            if addr == "127.0.0.1":
                self.launcher = LocalServerLauncher(conn_conf,
                                                    path=server_config.path)
            else:
                self.launcher = RemoteSSHServerLauncher(
                    conn_conf,
                    cred=SSHCred(server_config.username,
                                 key_path=server_config.ssh_key),
                    path=server_config.path,
                )
        else:
            self.launcher = _NullLauncher()

        self.launcher.start()

        self._chan = grpc.insecure_channel(
            f"{addr}:{port}",
            options=[("grpc.max_send_message_length", _100_MB),
                     ("grpc.max_receive_message_length", _100_MB)],
        )
        client = inference_pb2_grpc.InferenceStub(self._chan)
        upload_client = data_store_pb2_grpc.DataStoreStub(self._chan)
        self._devices = [d.id for d in server_config.devices if d.enabled]
        self._connection = Connection(client, upload_client)
        return self._connection
Exemple #3
0
def run():
    with grpc.insecure_channel("127.0.0.1:5567") as channel:
        stub = inference_pb2_grpc.InferenceStub(channel)
        response = stub.ListDevices(inference_pb2.Empty())
        print(response)