MCPcopy
hub / github.com/su-kaka/gcli2api / shutdown_server_async

Function shutdown_server_async

src/auth.py:952–978  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

950 """异步关闭OAuth回调服务器,避免阻塞主流程"""
951
952 def shutdown_server_async():
953 try:
954 # 设置一个标志来跟踪关闭状态
955 shutdown_completed = threading.Event()
956
957 def do_shutdown():
958 try:
959 server.shutdown()
960 server.server_close()
961 shutdown_completed.set()
962 log.info(f"已关闭端口 {port} 的OAuth回调服务器")
963 except Exception as e:
964 shutdown_completed.set()
965 log.debug(f"关闭服务器时出错: {e}")
966
967 # 在单独线程中执行关闭操作
968 shutdown_worker = threading.Thread(target=do_shutdown, daemon=True)
969 shutdown_worker.start()
970
971 # 等待最多5秒,如果超时就放弃等待
972 if shutdown_completed.wait(timeout=5):
973 log.debug(f"端口 {port} 服务器关闭完成")
974 else:
975 log.warning(f"端口 {port} 服务器关闭超时,但不阻塞主流程")
976
977 except Exception as e:
978 log.debug(f"异步关闭服务器时出错: {e}")
979
980 # 在后台线程中关闭服务器,不阻塞主流程
981 shutdown_thread = threading.Thread(target=shutdown_server_async, daemon=True)

Callers

nothing calls this directly

Calls 3

startMethod · 0.80
debugMethod · 0.80
warningMethod · 0.80

Tested by

no test coverage detected