Here is a blog explaining how to gracefully shutdown a GRPC server in kotlin.
Is this the only way to do it? Counting live calls and handling SIGTERM manually? This should have been normal behavior.
I couldn't find how to count live calls in python. Can someone point me to docs that will help?
gRPC Python servers have a (newish) method for this. Just call server.wait_for_termination()
Turns out there is a easy way instead of counting RPCs, here is how I got it done:
server = grpc.server(futures.ThreadPoolExecutor(max_workers=100))
{} = {}Impl()
add_{}Servicer_to_server({}, server)
server.add_insecure_port('[::]:' + port)
server.start()
logger.info('Started server at ' + port)
done = threading.Event()
def on_done(signum, frame):
logger.info('Got signal {}, {}'.format(signum, frame))
done.set()
signal.signal(signal.SIGTERM, on_done)
done.wait()
logger.info('Stopped RPC server, Waiting for RPCs to complete...')
server.stop(NUM_SECS_TO_WAIT).wait()
logger.info('Done stopping server')