<p><a href="https://medium.com/@fedor/shutting-down-grpc-services-gracefully-961a95b08f8" rel="nofollow noreferrer">Here</a> is a blog explaining how to gracefully shutdown a GRPC server in kotlin.</p>

<p>Is this the only way to do it? Counting live calls and handling SIGTERM manually? This should have been normal behavior.</p>

<p>I couldn't find how to count live calls in python. Can someone point me to docs that will help?</p>

<p>Turns out there is a easy way instead of counting RPCs, here is how I got it done:</p>

<pre><code>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')
</code></pre>
