-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathstart_model_serving.py
More file actions
52 lines (41 loc) · 1.4 KB
/
start_model_serving.py
File metadata and controls
52 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""
启动Model Serving API服务 - 独立进程模式
"""
import sys
import os
import signal
import time
# 添加src目录到Python路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from search_engine.model_service import ModelService
def signal_handler(signum, frame):
"""信号处理器"""
print("\n🛑 收到停止信号,正在关闭模型服务...")
sys.exit(0)
def main():
"""主函数"""
print("🚀 启动Model Serving API服务(独立进程)...")
print("=" * 60)
# 注册信号处理器
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
try:
# 创建并启动服务
model_service = ModelService()
print("📋 服务信息:")
print(f" 进程ID: {os.getpid()}")
print(f" 地址: http://0.0.0.0:8501")
print(f" 健康检查: http://localhost:8501/health")
print(f" 模型列表: http://localhost:8501/v1/models")
print(" 按 Ctrl+C 停止服务")
print("=" * 60)
# 启动服务(这会阻塞进程)
model_service.start_api_server(port=8501)
except KeyboardInterrupt:
print("\n🛑 模型服务已停止")
except Exception as e:
print(f"❌ 启动模型服务失败: {e}")
sys.exit(1)
if __name__ == "__main__":
main()