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
相关推荐
ValidationExpression3 小时前
LangChain1.0学习
学习·ai·langchain·fastapi
曲幽3 小时前
FastAPI缓存提速实战:手把手教你用Redis为接口注入“记忆”
redis·python·cache·fastapi·web·asyncio
wang6021252185 小时前
流式输出注意点
python·状态模式·fastapi
内存不泄露1 天前
基于 Spring Boot 的医院预约挂号系统(全端协同)设计与实现
java·vue.js·spring boot·python·flask
CCPC不拿奖不改名1 天前
基于FastAPI的API开发(爬虫的工作原理):从设计到部署详解+面试习题
爬虫·python·网络协议·tcp/ip·http·postman·fastapi
曲幽1 天前
FastAPI数据库实战:从SQLAlchemy原理到高效连接管理,告别性能瓶颈
python·sqlite·flask·fastapi·web·sqlalchemy·db
云和数据.ChenGuang1 天前
fastapi无法在微软的edge上运行程序
前端·edge·fastapi
simon_skywalker2 天前
FastAPI实战笔记(九) WebSocket
fastapi