uvicorn 启动重复加载 多次加载

目录

[uvicorn 启动重复加载 多次加载](#uvicorn 启动重复加载 多次加载)

解决方法1:

解决方法2:


uvicorn 启动重复加载 多次加载

fastapi_aa 是当前类

解决方法1:

python 复制代码
import uvicorn

from fastapi import FastAPI

app = FastAPI()


if __name__ == "__main__":
    if sys.gettrace() is not None or os.getenv("RUN_MODE") == "debug":
        uvicorn.run(app=app, host="0.0.0.0", port=45503, workers=1, reload=False)
    else:
        uvicorn.run(app="fastapi_aa:app", host="0.0.0.0", port=45503, workers=1, reload=True)

解决方法2:

python 复制代码
from prometheus_client import Counter, generate_latest, CollectorRegistry, multiprocess, CONTENT_TYPE_LATEST, make_asgi_app, Gauge


registry = CollectorRegistry()
# 定义 Prometheus 指标
CALL_COUNT = Counter(
    "live_asr_method_calls_total_part3", 
    "part3 Total number of method calls",
    ["method", "status"],registry=registry
)

registry_1 = CollectorRegistry(auto_describe=True)


@app.get("/metrics")
def metrics():
    return Response(generate_latest(registry), media_type="text/plain")

# @app.get('/metrics', response_class=Response)
# async def make_metrics_app():
#     logger.info(f"call get metrics")
#     registry = CollectorRegistry()
#     multiprocess.MultiProcessCollector(registry)

#     metrics_data = generate_latest(registry)
#     return Response(content=metrics_data, media_type=CONTENT_TYPE_LATEST)
相关推荐
IVEN_5 小时前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang7 小时前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮7 小时前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling7 小时前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮10 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽10 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健1 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽1 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers