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
相关推荐
hhcgchpspk5 小时前
flask服务端页面预防被爬措施
后端·python·flask·网络爬虫·防爬
LK_076 小时前
【FastAPI】基础篇 01|开始之前:API、HTTP 与 FastAPI 到底是什么
网络协议·http·fastapi
Blockbuater_drug2 天前
《经典机器学习实战》第 5 课:把模型做成 Web 应用(UFO)
flask·pickle·模型部署·web应用·机器学习上线·ufo数据集·rest接口
梅雅达编程笔记4 天前
下单不付款库存被占?Flask定时任务自动取消超时订单+回滚库存
flask·毕设·定时任务·电商系统·apscheduler·myd电商·超时订单
一枕槐安4876 天前
Qwen 通义千问本地部署与推理服务封装
fastapi·qwen·vllm·流式推理·openai兼容api·awq量化
在努力的前端小白6 天前
基于FastAPI+LangChain+LangGraph+Agent+多模态的AI Agent 有渔渔具网站
人工智能·langchain·vue·fastapi
薛定谔的猫-菜鸟程序员6 天前
软件架构设计师开发资料大全(从入门到精通)
后端·python·系统架构·flask·架构设计师
sun_weitao6 天前
用 FastAPI + MQTT 做一个 ESP32最小化跑通示例
中间件·vue·fastapi
峯5806 天前
一文学习FastAPI
学习·fastapi
TheBestRucy8 天前
从零构建企业级“中文法律智能问答系统”:FastAPI+Milvus+混合检索+真流式RAG实战
fastapi·milvus