googleapis/gax-python

Can't Override timeout with CallOptions

Opened this issue · 0 comments

I'm using Python to make a query to Google's Vision API to obtain labels from an image, but I'm not able to set a timeout in case I don't receive a response within a given time.

I'm using the following code based on Google's Documentation of CallOptions.

This is my code:

class GoogleQuery():

def __init__(self, VisionTools):
    self.client = vision.ImageAnnotatorClient()
    self.QueryOptions = google.gax.CallOptions(timeout=0.1)

... more init fields

def QueryImage(self, frame):
    image = types.Image(content=frame)

    # Make query to Google
    response = self.client.label_detection(image=image, options=self.QueryOptions)

I have tried passing directly the arguments into the call to Google without success, like this:

    def QueryImage(self, frame):

        # Convert frame to a type compatible with Google API
        image = types.Image(content=frame)

        # Make query to Google
        o1 = CallOptions(timeout = 0.1)
        response = self.client.label_detection(image=image, options=(o1))