what is _MultiThreadedRendezvous in grpc and how to parse it

Viewed 5077

I'm trying to send a grpc request and I'm expected to receive stream of message back. Instead I'm receiving a response as <_MultiThreadedRendezvous object>. Can anyone help me to understand why I'm receiving this and what should I do to extract the expected message from this object. The server is C++ and client is python in this case.

2 Answers

Please take a look at gRPC's example of streaming RPC. The _MultiThreadedRendezvous object is the library's representation of an RPC result. It is an iterable, you can use for to fetch all responses, or you can use list() to get all messages.

Using e.code() and e.details() helped me parsing it:

try:
    response = stub.SayHello(...)
except _MultiThreadedRendezvous as e:
    if e.code() == grpc.StatusCode.CANCELLED:
        pass 
        # process cancelled status

    elif e.code() == grpc.StatusCode.UNAVAILABLE and 'Connection reset by peer' in e.details():
        pass 
        # process unavailable status

    else:
        raise

Looking at the source code of that error helped me understand how to parse it.

Credit to this answer on another question.

Related