MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / run_server

Function run_server

lightx2v/server/main.py:18–88  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

16
17
18def run_server(args):
19 global _shutdown_requested
20 inference_service = None
21 rank = int(os.environ.get("LOCAL_RANK", 0))
22 world_size = int(os.environ.get("WORLD_SIZE", 1))
23
24 def _signal_handler(signum, frame):
25 global _shutdown_requested
26 if _shutdown_requested:
27 return
28 _shutdown_requested = True
29 logger.info(f"Server rank {rank} received shutdown signal")
30 if inference_service:
31 inference_service.stop_distributed_inference()
32 os._exit(0)
33
34 signal.signal(signal.SIGINT, _signal_handler)
35 signal.signal(signal.SIGTERM, _signal_handler)
36
37 try:
38 logger.info(f"Starting LightX2V server (Rank {rank}/{world_size})...")
39
40 if hasattr(args, "host") and args.host:
41 server_config.host = args.host
42 if hasattr(args, "port") and args.port:
43 server_config.port = args.port
44 if hasattr(args, "max_queue_size") and args.max_queue_size:
45 server_config.max_queue_size = int(args.max_queue_size)
46
47 task_manager.set_max_queue_size(server_config.max_queue_size)
48 logger.info(f"Task queue size set to {server_config.max_queue_size}")
49
50 if not server_config.validate():
51 raise RuntimeError("Invalid server configuration")
52
53 inference_service = DistributedInferenceService()
54 if not inference_service.start_distributed_inference(args):
55 raise RuntimeError("Failed to start distributed inference service")
56 logger.info(f"Rank {rank}: Inference service started successfully")
57
58 if rank == 0:
59 metric_port = int(os.environ.get("LIGHTX2V_METRIC_PORT", 8001))
60 if hasattr(args, "metric_port") and args.metric_port:
61 metric_port = int(args.metric_port)
62 server_process(metric_port=metric_port)
63 logger.info(f"Metrics server started on {server_config.host}:{metric_port}")
64
65 cache_dir = Path(server_config.cache_dir)
66 cache_dir.mkdir(parents=True, exist_ok=True)
67
68 api_server = ApiServer(max_queue_size=server_config.max_queue_size)
69 api_server.initialize_services(cache_dir, inference_service)
70
71 app = api_server.get_app()
72
73 logger.info(f"Starting FastAPI server on {server_config.host}:{server_config.port}")
74 uvicorn.run(app, host=server_config.host, port=server_config.port, log_level="info")
75 else:

Callers 1

mainFunction · 0.85

Calls 14

initialize_servicesMethod · 0.95
get_appMethod · 0.95
run_worker_loopMethod · 0.95
server_processFunction · 0.85
ApiServerClass · 0.85
infoMethod · 0.80
set_max_queue_sizeMethod · 0.80
validateMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected