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
相关推荐
郭庆汝2 小时前
FastAPI使用笔记
笔记·fastapi
放下华子我只抽RuiKe53 小时前
FastAPI 全栈后端(二):路由与数据模型
前端·人工智能·react.js·前端框架·html·fastapi
伊布拉西莫4 小时前
Flask 请求生命周期
后端·python·flask
XGeFei4 小时前
【Fastapi学习笔记(7)】—— Fastapi 中间件、前端跨域请求
笔记·学习·fastapi
叫我:松哥7 小时前
基于LSTM与ARIMA的城市空气质量分析与预测系统
人工智能·python·rnn·算法·机器学习·flask·lstm
叫我:松哥7 小时前
基于deepseek大语言模型的项目架构图设计与绘制系统
人工智能·语言模型·自然语言处理·架构·flask·bootstrap
li星野8 小时前
构建安全的文件上传系统:FastAPI + JWT 认证 + Streamlit 前端 + SQLite 数据库
数据库·安全·fastapi
动能小子ohhh20 小时前
DocForge平台的设计与开发--文件上传接口的实现
开发语言·人工智能·python·langchain·ocr·fastapi
XGeFei1 天前
【Fastapi学习笔记(6)】—— Fastapi文件上传、请求头自动转换
笔记·学习·fastapi