I am writing an async app (using Trio). I have an Application class with various async "handle_x_event" methods that get scheduled in the Trio nursery. Some such events need to trigger a gRPC call.
Currently, this only works if I create the channel and stub right when I need to use it:
class Application:
def __init__(self):
# various setup omitted
async def handle_keystrokes(self):
# handle some keys
async def handle_document_updates(self):
# handle document changes
async def handle_screen_updates(self):
async for _ in self.screen_update.events():
logging.debug("sending screen update")
req = self.make_request()
logging.debug("sending {!r}".format(req))
async with purerpc.insecure_channel('127.0.0.1', TABULA_PORT) as rpc_channel:
stub = imprimare_grpc.TabulaStub(rpc_channel)
response = await stub.UpdateDisplay(req)
logging.debug(response)
async def main():
async with trio.open_nursery() as nursery:
application = Application()
nursery.start_soon(application.handle_keystrokes)
nursery.start_soon(application.handle_document_updates)
nursery.start_soon(application.handle_screen_updates)
If I try to create the rpc_channel or the stub in my main function and pass it in to the Application class for use, then the await stub.UpdateDisplay(req) call never returns. There's no error message; that task just silently waits forever, and the server does not receive my request.
I want a long-lasting client connection. How can I set one up?
I am writing an async app (using Trio). I have an Application class with various async "handle_x_event" methods that get scheduled in the Trio nursery. Some such events need to trigger a gRPC call.
Currently, this only works if I create the channel and stub right when I need to use it:
If I try to create the rpc_channel or the stub in my main function and pass it in to the Application class for use, then the
await stub.UpdateDisplay(req)
call never returns. There's no error message; that task just silently waits forever, and the server does not receive my request.I want a long-lasting client connection. How can I set one up?