【问题标题】:How run a flask app packaged as pex in gunicorn?如何在 gunicorn 中运行打包为 pex 的烧瓶应用程序?
【发布时间】:2019-04-10 06:55:27
【问题描述】:

我打算将我的烧瓶应用程序打包为一个 pex 以进行自包含分发,想知道如何在 Gunicorn 中运行 pex?或者甚至可以将 gunicorn 打包在可执行文件中,所以当我运行 pex 时,flask 应用程序会在 gunicorn 中运行。这有可能吗?

【问题讨论】:

    标签: flask gunicorn pex


    【解决方案1】:

    我组装了一个示例应用程序,展示了如何使用 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 文件中。

    【讨论】:

    • @alwaysprep 你能举个例子吗?
    • @Germaniero 你在构建过程中使用裤子吗?如果是这样,请转到 .pex 文件所在的 dist 文件。并写: "PEX_SCRIPT=gunicorn ./{pex_file_name}.pex {path_to_your_app}:app" 您需要将 gunicorn 添加到您的 3rdparty。
    【解决方案2】:

    只是关于@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
    

    【讨论】:

      猜你喜欢
      • 2020-05-23
      • 2012-11-19
      • 2018-07-06
      • 2015-07-05
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 2020-04-16
      • 2018-10-25
      相关资源
      最近更新 更多