【发布时间】:2019-04-10 06:55:27
【问题描述】:
我打算将我的烧瓶应用程序打包为一个 pex 以进行自包含分发,想知道如何在 Gunicorn 中运行 pex?或者甚至可以将 gunicorn 打包在可执行文件中,所以当我运行 pex 时,flask 应用程序会在 gunicorn 中运行。这有可能吗?
【问题讨论】:
我打算将我的烧瓶应用程序打包为一个 pex 以进行自包含分发,想知道如何在 Gunicorn 中运行 pex?或者甚至可以将 gunicorn 打包在可执行文件中,所以当我运行 pex 时,flask 应用程序会在 gunicorn 中运行。这有可能吗?
【问题讨论】:
我组装了一个示例应用程序,展示了如何使用 Pex 打包 Flask 应用程序并使用 Gunicorn 运行生成的 pex 文件,请参见此处: https://github.com/wolkenarchitekt/pex-flask-gunicorn-example
这些是打包和运行应用程序的基本命令:
python setup.py sdist
pex -vv -r requirements.txt -D . -o ./hello-service.pex
PEX_SCRIPT=gunicorn ./hello-service.pex hello_service.main:app -b :8000
如您所见,Gunicorn 甚至被打包在 pex 文件中。
【讨论】:
只是关于@ifischer 答案的更新,(最近引入的)-c 旨在将脚本作为 pex 的入口点
pip3 wheel -w . .
pex --python=python3 -r requirements.txt -f . -o hello-service.pex -c gunicorn
./hello-service.pex hello_service.main:app -b :8000
【讨论】: