gunicorn 和 uvicorn部署fastapi 或者flask

gunicorn 和 uvicorn一起部署fastapi 或者flask

安装需要的包

bash 复制代码
pip install gunicorn uvicorn greenlet  eventlet gevent

后台代码

Server.py 文件中有app 变量

启动

bash 复制代码
# http 服务 timeout 单位s
gunicorn -k uvicorn.workers.UvicornWorker    Server:app --bind 0.0.0.0:5665 --workers 2 --timeout 100

# https 服务
gunicorn -k uvicorn.workers.UvicornWorker  --certfile=./configs/a.pem --keyfile=./configs/a-key.pem  Server:app --bind 0.0.0.0:5665 --workers 2 --timeout 520 

可能遇到的问题

如果遇到报错

Error: class uri 'uvicorn.workers.UvicornWorker' invalid or not found:

Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 135, in load_class mod = import_module('.'.join(components)) File "/usr/lib64/python2.7/importlib/**init** .py", line 37, in import_module **import** (name) ImportError: No module named uvicorn.workers

是因为环境中gunicorn 有冲突,需要指定安装环境的gunicorn

bash 复制代码
 /your_env_path/anaconda3/envs/your_env_name/bin/gunicorn -k uvicorn.workers.UvicornWorker  --certfile=./configs/a.pem --keyfile=./configs/a-key.pem  imageSegSimServer:app --bind 0.0.0.0:5665 --workers 2 --timeout 520
相关推荐
向日的葵0061 小时前
CSDN博客文章-爪印之约宠物收养管理系统
mysql·css3·html5·fastapi·宠物
码界筑梦坊2 小时前
119-基于Python的各类企业排行数据可视化分析系统
开发语言·python·信息可视化·数据分析·毕业设计·echarts·fastapi
颂love17 小时前
健康打卡系统项目总结
fastapi·sqlalchemy·全栈开发·dify集成
展示猪肝21 小时前
Vue2 + FastAPI + Dify 实现 AI 医疗预检分诊助手:从问诊追问到医生审核闭环
人工智能·vue·fastapi·dify
辞忧九千七1 天前
前后端分离架构实战与项目落地:AI智能学习笔记管理系统
python·html·axios·css3·fastapi·dify
深兰科技1 天前
深兰科技签约乌兹别克斯坦智慧城市项目,推动中国AI出海规模化
人工智能·beautifulsoup·numpy·智慧城市·fastapi·matplotlib·深兰科技
码界筑梦坊1 天前
118-基于Python的游戏账号数据可视化分析系统
python·游戏·信息可视化·毕业设计·pandas·fastapi
rising start1 天前
InsightEdu - 轻量智能学习平台
javascript·axios·css3·html5·fastapi·orm·dify
小李云雾1 天前
慧校坊-二手校园交易平台-------项目总结
数据库·后端·程序人生·fastapi·项目
码界筑梦坊1 天前
361-基于Python的空气质量气候数据分析预测系统
python·信息可视化·数据分析·flask·vue·毕业设计