Streaming server response

49 views
Skip to first unread message

Eric Chamberlain

unread,
Jan 25, 2024, 7:06:10 PM1/25/24
to grpc.io
I am trying to perform one operation, where the operation may send multiple messages to the client to inform them of the operation's status. The operation is wrapped in an `asyncio.run` context. So I need to be able to send messages _while in the context of the asyncio operation_. Yes, I understand this blocks other requests from being processed. This is OK for this use case.

I was hoping that the `grpc._server._Context` had something like `send`, or `write`, which accepted a streaming object. Alas, `yield` is used. I don't have an iterator, and there's no way to untangle the operation with an iterator that lives outside of the operation. I'm hoping there's some API feature I'm missing.

Maybe if I use the Asyncio API (https://grpc.github.io/grpc/python/grpc_asyncio.html#grpc.aio.ServicerContext.write) it would do what I want to do?

Thank you!

Eric

Eric Chamberlain

unread,
Jan 25, 2024, 7:31:10 PM1/25/24
to grpc.io
I figured it out. I transformed this service to use the asyncio api and used the `Context.write` method. It works beautifully! Unbelievable! What a great library. Thank you!
Reply all
Reply to author
Forward
0 new messages