40 lines
954 B
Python
40 lines
954 B
Python
# Gunicorn 配置文件
|
|
|
|
# 基本配置
|
|
bind = "0.0.0.0:5002"
|
|
workers = 4
|
|
threads = 4
|
|
timeout = 120
|
|
worker_class = "gthread"
|
|
|
|
# SSL 配置(如需要)
|
|
# certfile = "/etc/letsencrypt/live/api.valuefrontier.cn/fullchain.pem"
|
|
# keyfile = "/etc/letsencrypt/live/api.valuefrontier.cn/privkey.pem"
|
|
|
|
# 日志配置
|
|
loglevel = "info"
|
|
accesslog = "-"
|
|
errorlog = "-"
|
|
|
|
# 预加载应用(在 fork 前加载,加快 worker 启动)
|
|
preload_app = True
|
|
|
|
|
|
def on_starting(server):
|
|
"""主进程启动时调用"""
|
|
print("Gunicorn 主进程启动...")
|
|
|
|
|
|
def post_fork(server, worker):
|
|
"""Worker 进程 fork 后调用"""
|
|
print(f"Worker {worker.pid} 已启动")
|
|
|
|
|
|
def when_ready(server):
|
|
"""服务准备就绪时调用,初始化缓存"""
|
|
print("Gunicorn 服务准备就绪,开始初始化...")
|
|
from app_vx import app, init_sywg_industry_cache
|
|
with app.app_context():
|
|
init_sywg_industry_cache()
|
|
print("初始化完成!")
|