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

Function generate

tests/ce/deploy/deploy.py:463–505  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

461 next_response_time = start_time
462
463 def generate():
464 nonlocal next_response_time
465 while True:
466 health, msg = is_server_running()
467 now = time.time()
468
469 elapsed = time.time() - start_time
470
471 if health:
472 ports_status = {
473 "api_port": FD_API_PORT if is_port_in_use(FD_API_PORT) else None,
474 "queue_port": FD_ENGINE_QUEUE_PORT if is_port_in_use(FD_ENGINE_QUEUE_PORT) else None,
475 "metrics_port": FD_METRICS_PORT if is_port_in_use(FD_METRICS_PORT) else None,
476 }
477 msg["status"] = "服务启动完成"
478 msg["ports_status"] = ports_status
479 yield json.dumps(msg, ensure_ascii=False) + "\n"
480 break
481
482 if elapsed >= timeout:
483
484 def tail_file(path, lines=50):
485 try:
486 with open(path, "r", encoding="utf-8", errors="ignore") as f:
487 return "".join(f.readlines()[-lines:])
488 except Exception as e:
489 return f"[无法读取 {path}]: {e}, {str(traceback.format_exc())}\n"
490
491 result = f"服务启动超时,耗时:[{timeout}s]\n\n"
492 result += "==== server.log tail 50 ====\n"
493 result += tail_file("server.log")
494 result += "\n==== log/workerlog.0 tail 50 ====\n"
495 result += tail_file("log/workerlog.0")
496
497 yield result
498 break
499
500 if now >= next_response_time:
501 msg["status"] = f"服务启动中,耗时:[{int(elapsed)}s]"
502 yield json.dumps(msg, ensure_ascii=False) + "\n"
503 next_response_time += response_interval
504
505 time.sleep(interval)
506
507 return Response(generate(), status=200, content_type="text/plain")
508

Callers 3

wait_for_inferFunction · 0.70
runMethod · 0.50
test_handlerMethod · 0.50

Calls 4

is_server_runningFunction · 0.85
is_port_in_useFunction · 0.85
tail_fileFunction · 0.85
sleepMethod · 0.45

Tested by 1

test_handlerMethod · 0.40