7

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.

rajesh
  • 79
  • 1
  • 5

2 Answers2

7

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.

Lidi Zheng
  • 1,801
  • 8
  • 13
  • What you shared is really helpful. But sometime I receive no messages from that iterator sometimes I do. Have you experienced that. @lidi – rajesh Aug 20 '20 at 09:19
  • There are many possibility that could lead to that behavior. Generally, client should receive all the messages sent by peer. If you believe it is a bug in gRPC library, please create a reproduction case and submit an issue to https://github.com/grpc/grpc/issues. – Lidi Zheng Aug 21 '20 at 17:57
  • No worries. I don't think it is due to grpc library. Something wrong on my side of code. – rajesh Aug 24 '20 at 12:09
3

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.

Voy
  • 5,286
  • 1
  • 49
  • 59