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
相关推荐
llilay4 小时前
企业级FastAPI后端模板搭建(五)初始化数据
fastapi
冰暮流星7 小时前
flask之app.py讲解
后端·python·flask
冰暮流星8 小时前
flask之模版渲染
后端·python·flask
冰暮流星9 小时前
python之flask框架讲解-准备
开发语言·python·flask
CaffeinePro1 天前
FastAPI自动接口文档定制与美化、权限管控
后端·fastapi
2501_942389551 天前
AI才女”罗福莉加盟小米
matplotlib·sublime text·广度优先·gunicorn
大数据魔法师1 天前
FastAPI零基础教程(六)- 数据库集成,SQLModel无缝衔接
python·fastapi
Alan_752 天前
Python FastAPI 高性能 API 开发:三个核心优化方向
api·fastapi
编码者卢布2 天前
【Azure Storage Account】跨存储账号复制 Blob 会产生大量网络流量费用吗?
microsoft·flask·azure
曲幽6 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry