[Python] Can I use asyncio.Event.wait() instead of gRPC await server.wait_for_termination()

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    The typical approach for gRPC AsyncIO is

    await server.start()
    try:
    await server.wait_for_termination()
    except:
    ...


    But I was wondering rather than dealing with it via a hard stop because wait_for_termination just blocks forever until canceled if I can use asyncio.Event.wait() so I can trigger the termination of the server more cleanly.

    Looking at the code for wait_for_termination it goes down to some C bindings so I am not sure if it may be doing anything else special or if asyncio.Event.wait() which I presume would use asyncio loop implementation more effectively (like Windows has it's own loop implementation that's different from UNIX).

    As for my integration tests, them seem to pass so I am.

    Continue reading...

Compartilhe esta Página