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
相关推荐
larance8 小时前
Gunicorn + Nginx+systemd 配置flask
nginx·flask·gunicorn
Shi_haoliu9 小时前
python安装操作流程-FastAPI + PostgreSQL简单流程
python·postgresql·fastapi
曲幽12 小时前
FastAPI不止于API:手把手教你用Jinja2打造动态Web页面
python·fastapi·backend·jinja2·full stack·template engine·web development
PD我是你的真爱粉13 小时前
FastAPI中间件与路由
中间件·fastapi
历程里程碑16 小时前
普通数组-----除了自身以外数组的乘积
大数据·javascript·python·算法·elasticsearch·搜索引擎·flask
Hello.Reader1 天前
Flink 对接 Azure Blob Storage / ADLS Gen2:wasb:// 与 abfs://(读写、Checkpoint、插件与认证)
flink·flask·azure
Swift社区1 天前
Gunicorn 与 Uvicorn 部署 Python 后端详解
开发语言·python·gunicorn
Coinsheep1 天前
SSTI-flask靶场搭建及通关
python·flask·ssti
IT实战课堂小元酱1 天前
大数据深度学习|计算机毕设项目|计算机毕设答辩|flask露天矿爆破效果分析系统开发及应用
人工智能·python·flask
码农阿豪1 天前
Flask应用上下文问题解析与解决方案:从错误日志到完美修复
后端·python·flask