vmagamedov / grpclib

Pure-Python gRPC implementation for asyncio
http://grpclib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
938 stars 91 forks source link

Re-connect after getting StreamTerminatedError #169

Open ahmdrz opened 1 year ago

ahmdrz commented 1 year ago

Is there any way to reconnect after getting StreamTerminatedError?

max_retries = 5
for retries in range(max_retries):
    try:
        await stream.send_message(...)
        break
    except StreamTerminatedError as e:
        if (retries + 1) == max_retries:
            raise e
        # Reconnect here
        await asyncio.sleep(10)

I wanted to reconnect to the channel and try sending a message again without creating another context or whole stream connection. Are there any tricks? I just wanted to ensure about sending a specific message.