Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I have a long-lasting client? #29

Open
inklesspen opened this issue May 12, 2021 · 0 comments
Open

How do I have a long-lasting client? #29

inklesspen opened this issue May 12, 2021 · 0 comments

Comments

@inklesspen
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant