Is the idea to provide asynchronous / async-friendly APIs on the stub, 
service, or both? Based on my experience, I think designing an asynchronous 
api for rpc services is probably trickier, particularly for streaming 
replies. The simple and developer-user friendly generator idiom for 
streaming replies doesn't translate to asyncio coroutines, which can only 
return once. Coroutine generators are not implemented in python 3.5, see 
https://www.python.org/dev/peps/pep-0492/#coroutine-generators

What I think this means is that an asynchronous rpc method with a streaming 
reply would have to push elements onto a queue or other object representing 
a stream, rather than returning them directly. Something like the following:

async def MethodWithStreamingReplies(request, reply_stream):
    while some_condition:
        item = await some_coroutine()
        reply_stream.push(item)
    reply_stream.close()

Note that the reply stream needed to be closed explicitly; unlike a 
generator which raises StopIteration once it is exhausted, the reply stream 
presumably needs a terminating sentinel to notify its consumer that it has 
been exhausted.


On Monday, 12 September 2016 12:47:21 UTC-4, Nathaniel Manista wrote:
>
> There's been a <https://github.com/grpc/grpc/issues/4629> great 
> <https://github.com/grpc/grpc/issues/6046> deal 
> <https://github.com/grpc/grpc/issues/7910> of 
> <https://groups.google.com/d/msg/grpc-io/OyREQk-TnbI/drBlO6hQCgAJ> 
> interest 
> <https://groups.google.com/forum/#!searchin/grpc-io/python%7Csort:relevance/grpc-io/17Cd5lgtuhw/tR5dJ8hgCgAJ>
>  
> in enhancing gRPC Python to work with asynchronous frameworks and language 
> features. While gRPC has been open source for some time we haven't until 
> now done much in the way of community-driven development; asynchronous gRPC 
> Python is a chance to try out a more direct open process. Please 
> participate!
>
> For those of you that have found workarounds 
> <https://github.com/grpc/grpc/issues/4629#issuecomment-244944914> and drafted 
> patches <https://github.com/grpc/grpc/issues/7910#issuecomment-243290904>: 
> you probably know more about the work ahead than I do, and I'd especially 
> appreciate your involvement.
>
> Process-wise, I have drafted this initial document 
> <https://github.com/grpc/grpc-experiments/blob/master/python/async/README.md>,
>  
> and for at least initial design I'd like to proceed by pull requests 
> fleshing out the document with proposals and plans. Pull requests to gRPC 
> itself will also of course be part of the conversation - please remember to 
> include test coverage not only for code health's sake but also as an 
> illustration of new behavior.
>
> Looking forward,
> -Nathaniel
>

-- 
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/ea5b8b95-a0be-446f-9f6c-e1dced4fc28b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to