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)
相关推荐
独行soc2 小时前
2025年渗透测试面试题总结-66(题目+回答)
java·网络·python·安全·web安全·adb·渗透测试
Y学院4 小时前
Python 数据分析:从新手到高手的“摸鱼”指南
python·数据分析
深耕AI5 小时前
【PyTorch训练】准确率计算(代码片段拆解)
人工智能·pytorch·python
eqwaak05 小时前
科技信息差(9.12)
开发语言·python·科技·量子计算
Blossom.1185 小时前
从“能写”到“能干活”:大模型工具调用(Function-Calling)的工程化落地指南
数据库·人工智能·python·深度学习·机器学习·计算机视觉·oracle
蒋星熠5 小时前
破壁者指南:内网穿透技术的深度解构与实战方法
网络·数据库·redis·python·websocket·网络协议·udp
shizidushu5 小时前
使用 Pyinstaller 打包 PPOCRLabel
python·pyinstaller
Q_Q19632884756 小时前
python+springboot+uniapp微信小程序题库系统 在线答题 题目分类 错题本管理 学习记录查询系统
spring boot·python·django·uni-app·node.js·php
Rhys..6 小时前
.gitignore文件的作用及用法
python·github