On Wed, Nov 29, 2017 at 1:29 PM, <[email protected]> wrote: > Trying to understand the ability for gRPC to use async/await available in > python 3.6. >
Right now there is no known compatibility. Right now I'm modifying the grpc tutorial code to try to understand how > async will work. > > I'm using the route_guide examples and have modified the code slightly. > > Is there a gRPC equivalent for async for ? > Not at the moment. Right now, this returns the error: "TypeError: 'async for' requires an > object with __aiter__ method, got _Rendezvous" , which makes sense. But is > there a way around this so that I don't need to block while waiting for > responses? > The .future methods were intended to cover asynchronous application use cases - so no, you don't have to block while waiting for responses if you don't mind a thread running in the background (one thread per channel no matter how many RPCs are running via the channel). Looked through the github issues, and it seems https://github.com/grpc/grpc/issues/6046 > talks about solutions to this, but the solution is to spawn another thread? > Well, when you call my_stub.MyRpcMethod.future a thread is spawned inside the channel (if needed) so you shouldn't have to spawn any *additional* thread of your own. Can async not be used with gRPC without needing threads? > > async def guide_route_chat(stub): > responses = stub.RouteChat(generate_messages()) > await asyncio.sleep(1) > async for response in responses: > print("Received message %s at %s" % (response.message, response. > location)) > > > async def tasks(num_tasks): > for elem in range(num_tasks): > print ("task %d" %(elem)) > await asyncio.sleep(1.0) > > def run(): > channel = grpc.insecure_channel('localhost:50051') > stub = route_guide_pb2_grpc.RouteGuideStub(channel) > asyncio.ensure_future(guide_route_chat(stub)) > loop = asyncio.get_event_loop() > loop.run_until_complete(tasks(10)) > As of today asynchronicity in gRPC Python uses threads and requires that threads work the way the Python language standard specifies that they work. Relaxing this restriction is one of the big projects we have planned for 2018. -N -- 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/CAEOYnARdAXMPRReK6eS4PPkZs0tyCKWuOt1aG-ESUiYQbizJ5g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
smime.p7s
Description: S/MIME Cryptographic Signature
