def close_api_gracefully(apis): try: for api in apis.values(): process = api['process'] childs = get_child_pids(process.pid) for p in childs: os.kill(p, signal.SIGTERM) sys.stdout.flush() process.terminate() process.join() sys.stdout.flush() except KeyboardInterrupt: sys.exit(0)
def close_api_gracefully(apis): try: for api in apis.values(): process = api['process'] childs = get_child_pids(process.pid) for p in childs: try: os.kill(p, signal.SIGTERM) except Exception: p.kill() sys.stdout.flush() process.terminate() process.join() sys.stdout.flush() if ray_based: os.system('ray stop --force') except KeyboardInterrupt: sys.exit(0) except psutil.NoSuchProcess: pass