gunicorn 和 uvicorn部署fastapi 或者flask
安装需要的包
pip install gunicorn uvicorn greenlet eventlet gevent
后台代码
Server.py 文件中有app 变量
启动
# 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
/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
原文地址:https://blog.csdn.net/Magicapprentice/article/details/143801960
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!