如何在gunicorn中运行打包为pex的烧瓶应用程序?

时间:2018-11-06 20:18:51

标签: flask gunicorn pex

我正计划将我的flask应用程序打包为自包含分发的pex,想知道如何在Gunicorn中运行pex?甚至可能将gunicorn打包在可执行文件中,因此当我运行pex时,flask应用程序以gunicorn运行。那有可能吗?

2 个答案:

答案 0 :(得分:1)

我组装了一个示例应用程序,显示了如何使用Pex打包Flask应用程序以及如何使用Gunicorn运行生成的pex文件,请参见此处: https://github.com/ifischer/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文件中。

答案 1 :(得分:0)

只是有关@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
相关问题