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

Function get_config

tests/ce/deploy/deploy.py:407–452  ·  view source on GitHub ↗

获取当前server配置

()

Source from the content-addressed store, hash-verified

405
406@app.route("/config", methods=["GET"])
407def get_config():
408 """获取当前server配置"""
409 health, msg = is_server_running()
410
411 if not health:
412 return Response(json.dumps(msg, ensure_ascii=False), status=500, content_type="application/json")
413
414 if not os.path.exists("log/api_server.log"):
415 return Response(
416 json.dumps({"message": "api_server.log不存在"}, ensure_ascii=False),
417 status=500,
418 content_type="application/json",
419 )
420
421 try:
422 # 筛选出包含"args:"的行
423 with open("log/api_server.log", "r") as f:
424 lines = [line for line in f.readlines() if "args:" in line]
425
426 last_line = lines[-1] if lines else ""
427
428 # 使用正则表达式提取JSON格式的配置
429 match = re.search(r"args\s*[::]\s*(.*)", last_line)
430 if not match:
431 return Response(
432 json.dumps({"message": "api_server.log中没有args信息,请检查log"}, ensure_ascii=False),
433 status=500,
434 content_type="application/json",
435 )
436
437 # 尝试解析JSON
438 config_json = match.group(1).strip()
439 config_data = ast.literal_eval(config_json)
440 print("config_data", config_data, type(config_data))
441 return Response(
442 json.dumps({"server_config": config_data}, ensure_ascii=False), status=200, content_type="application/json"
443 )
444
445 except Exception as e:
446 error_msg = f"{e}, {str(traceback.format_exc())}"
447 print(error_msg)
448 return Response(
449 json.dumps({"message": "api_server.log解析失败,请检查log", "error": error_msg}, ensure_ascii=False),
450 status=500,
451 content_type="application/json",
452 )
453
454
455@app.route("/wait_for_infer", methods=["POST"])

Callers

nothing calls this directly

Calls 3

is_server_runningFunction · 0.85
printFunction · 0.85
existsMethod · 0.45

Tested by

no test coverage detected