Can you try “stream.cancel()”? The “cancel()” method is available for both client context and server context. See *class *grpc.*RpcContext in * *https://grpc.io/grpc/python/grpc.html#client-side-context <https://grpc.io/grpc/python/grpc.html#client-side-context>.*
On Thu, Mar 14, 2019 at 23:54 Mark Nuttall-Smith <[email protected]> wrote: > Hi, > > Using Python gRPC, I would like to be able to cancel a long-running > unary-stream call from the client side, when a `threading.Event` is set. > > def application(stub: StreamsStub, event: threading.Event): > stream = stub.Application(ApplicationStreamRequest()) > try: > for resp in stream: > print(resp) > except grpc.RpcError as e: > print(e) > > For the time being I am cancelling the stream using the `channel.close()` > method, but of course this closes all connections rather than just this > stream. > > Could someone suggest how I can use the event to cancel the stream > iterator? > > Thanks, Mark > > (cross post from SO: > https://stackoverflow.com/questions/55160210/python-grpc-cancel-unary-stream-call-from-client-side > ) > > -- > You received this message because you are subscribed to the Google Groups " > grpc.io" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/grpc-io. > To view this discussion on the web visit > https://groups.google.com/d/msgid/grpc-io/2b7ed001-d5b9-452b-b4dd-fbcb905687b3%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/2b7ed001-d5b9-452b-b4dd-fbcb905687b3%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CAMC1%3DjcE6VKNWsmx90d--qsSFcc5c1U4_Xy%3D8mSWLsauk3ueGA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
