Peter Litvak
Peter Litvak

Reputation: 95

Is there a way to specify a connection timeout for the client?

I'd imagine this should be a property of a channel but the channel doesn't have anything related to the connection configuration.

Upvotes: 0

Views: 58

Answers (1)

mimarcel
mimarcel

Reputation: 695

You can set the request timeout like this:

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import service_pb2_grpc, service_pb2

stub = service_pb2_grpc.V2Stub(ClarifaiChannel.get_grpc_channel())

if __name__ == '__main__':
  YOUR_CLARIFAI_API_KEY = 'addyourclarifaikeyhere'
  auth_metadata = (('authorization', f'Key {YOUR_CLARIFAI_API_KEY}'),)

  resp = stub.ListModels(service_pb2.ListModelsRequest(),
                         metadata=auth_metadata,
                         timeout=0.0001)
  print(resp)

Looking at the list of configurations for a grpc channel, there doesn't seem to be a global connection timeout.

Upvotes: 0

Related Questions