python - 从 Pex 中导入 Pex 的模块是否可以暴露?

标签 python fastapi asgi pants nginx-unit

来自 https://github.com/pantsbuild/pex/issues/1181 的交叉发布因为我真的不知道该去哪里问这个问题。

我正在使用 Nginx Unit,它为我的 FastAPI 应用程序提供了 ASGI 配置。它工作正常,但我不知道如何将它与 PEX 一起使用。

我已将其附加在下面,但重点是 Nginx Unit 有一个 Python 插件,它正在寻找“模块”和“可调用”。

现在看起来是“apigateway.main:app”,类似于 uvicorn 或您正在使用的任何其他服务器实现。与 uvicorn、gunicorn 或其他任何东西不同 - 我不认为我可以在我的 pex 文件中打包任何其他工具并使用 PEX_SCRIPT。

对于是否/如何在 pex 之外公开模块和变量有什​​么建议吗?

{
    "listeners": {
        "*:80": {
            "pass": "routes"
        }
    },
    "routes": [
        {
            "action": {
                "pass": "applications/api"
            }
        }
    ],
    "applications": {
        "api": {
            "type": "python 3.9",
            "path": "/app",
            "module": "apigateway.main",
            "callable": "app",
            "limits": {
                "requests": 100
            },
            "processes": {}
        }
    },
    "access_log": "/var/log/access.log"
}

最佳答案

这个问题在 Github 票证 ( https://github.com/pantsbuild/pex/issues/1181 ) 中得到了回答:

All the traditional language here is meant to segue to the recent venv pex tool feature released with Pex 2.1.22. If you build your PEX file with venv support (add --include-tools to the Pex command line) then you gain the ability to create a venv from your PEX file. Doing so is a one-time manual step on the target machine or image:

PEX_TOOLS=1 ./my.pex venv /app That will create a virtual environment containing your app and its dependencies under /app. You can point Nginx Unit there with home. I've done all this over at https://github.com/jsirois/pex-issues-1181 to prove it works.

关于python - 从 Pex 中导入 Pex 的模块是否可以暴露?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65802442/

相关文章:

python - 无法启动 Django 应用程序

python - 如何从 .egg 文件夹离线安装新版本的 python 包?

python - 使用 Fast API python web 框架进行行为驱动开发 (BDD) 测试

python - Gunicorn gevent workers vs Uvicorn ASGI

django - 带有 Django channel 的 heroku 的正确 procfile/要求是什么?

python - 根据最后 3 个字符对文本进行排序

python模块__init__函数

python - 上传多个文件 UploadFiles FastAPI

python-asyncio - FastAPI如何将ZMQ添加到事件循环