MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / switch_service

Function switch_service

tests/ce/deploy/deploy.py:308–374  ·  view source on GitHub ↗

切换模型服务

()

Source from the content-addressed store, hash-verified

306
307@app.route("/switch", methods=["POST"])
308def switch_service():
309 """切换模型服务"""
310 # kill掉已有服务
311 stop_server()
312 time.sleep(10)
313
314 try:
315 base_config = DEFAULT_PARAMS
316
317 override_config = request.get_json() or {}
318
319 final_config = merge_configs(base_config, override_config)
320
321 global FD_API_PORT
322 global FD_ENGINE_QUEUE_PORT
323 global FD_METRICS_PORT
324 FD_API_PORT = final_config["--port"]
325 FD_ENGINE_QUEUE_PORT = final_config["--engine-worker-queue-port"]
326 FD_METRICS_PORT = final_config["--metrics-port"]
327
328 # 构建命令
329 cmd = build_command(final_config)
330 except Exception as e:
331 error_msg = f"Failed to switch service: {e}, {str(traceback.format_exc())}"
332 print(error_msg)
333 return Response(
334 json.dumps({"status": "error", "message": error_msg}, ensure_ascii=False),
335 status=500,
336 content_type="application/json",
337 )
338
339 print("cmd", cmd)
340
341 try:
342 # 设置环境变量并启动进程
343 env = os.environ.copy()
344
345 with open(LOG_FILE, "w") as log:
346 process = subprocess.Popen(cmd, stdout=log, stderr=log, env=env, start_new_session=True)
347
348 # 保存进程ID,port到yaml文件
349 with open(PID_FILE, "w") as f:
350 yaml.dump({"PID": process.pid, "PORT": final_config["--port"]}, f)
351
352 json_data = {
353 "status": "success",
354 "message": "服务启动命令已执行",
355 "pid": process.pid,
356 "config": final_config,
357 "log_file": LOG_FILE,
358 "cmd": cmd,
359 "port_info": {
360 "api_port": FD_API_PORT,
361 "queue_port": FD_ENGINE_QUEUE_PORT,
362 "metrics_port": FD_METRICS_PORT,
363 },
364 }
365

Callers

nothing calls this directly

Calls 7

stop_serverFunction · 0.85
merge_configsFunction · 0.85
build_commandFunction · 0.85
printFunction · 0.85
dumpMethod · 0.80
sleepMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected