2

python | 使用 gunicorn 运行 flask

 1 month ago
source link: https://benpaodewoniu.github.io/2024/03/24/python203/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

python | 使用 gunicorn 运行 flask

这里的环境是

sudo pip install gunicorn

把上面的 python 安装完之后,除了建立 python3.7 的软链接外,还要建立 python 和 python3 的,即加上

sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python3
sudo ln -s /usr/local/src/python37/bin/python3.7 /usr/bin/python

然后运行 python 看是否正常。

然后执行(我的入口文件叫做 api.py)

gunicorn -w 4 -b 0.0.0.0:8081 api:app &

这个时候会报错

File "/usr/lib/command-not-found", line 27, in <module>
from CommandNotFound.util import crash_guard
ModuleNotFoundError: No module named 'CommandNotFound'

这是环境变量有关

sudo vim /etc/profile
在文件后面添加
export PATH=$PATH:/usr/local/src/python37/bin
然后让配置生效
source /etc/profile

此时再次执行

gunicorn -w 4 -b 0.0.0.0:8081 api:app &

就可以了。

但是,我觉得即便是什么都不配置,直接执行也可以,比如

/usr/local/src/python37/bin/python3.7 /usr/local/src/python37/bin/gunicorn -w 4 -b 0.0.0.0:8081 api:app &

不过,我没直接用过,有想用的可以尝试一下。

如果想要 killgunicorn,可以用

pkill gunicorn

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK