为什么枪支未能在PY文件中找到属性?

发布于 2025-02-01 09:20:24 字数 1064 浏览 2 评论 0原文

我有一个dashboard.py包含以下代码的文件:

    def run_explainer_dashboard(
    bucket_name: str,
    blob_dashboard_config: str,
    explainer_path: Union[str, "PathLike[str]"]
) -> ExplainerDashboard:
    ...
    return dashboard

if __name__ == "__main__":
    from a.settings import (
        BLOB_DASHBOARD_CONFIG,
        BUCKET_NAME
    )

    dashboard = run_explainer_dashboard(
        bucket_name=BUCKET_NAME,
        blob_dashboard_config='dashboard.yaml',
        explainer_path="...",
    )

    dashboard.run(
        host="0.0.0.0", port=int(os.environ.get("PORT", 8080)), use_waitress=True
    )

当我运行gunicorn运行dashboard.py使用以下代码: gunicorn - Bind 127.0.0.1:8080 -chdir〜 /.../ src dashboard:dashboard -termout 0,我收到一个错误消息说:

未能在“仪表板”中找到属性'仪表板。

如果我删除如果__name__ ==“ __ main __”:,则gunicorn有效。

为什么是这样?

如果要保留> __name __ ==“ __ -main __”:,如何使用Gunicorn命令?

I have a dashboard.py file containing the code below:

    def run_explainer_dashboard(
    bucket_name: str,
    blob_dashboard_config: str,
    explainer_path: Union[str, "PathLike[str]"]
) -> ExplainerDashboard:
    ...
    return dashboard

if __name__ == "__main__":
    from a.settings import (
        BLOB_DASHBOARD_CONFIG,
        BUCKET_NAME
    )

    dashboard = run_explainer_dashboard(
        bucket_name=BUCKET_NAME,
        blob_dashboard_config='dashboard.yaml',
        explainer_path="...",
    )

    dashboard.run(
        host="0.0.0.0", port=int(os.environ.get("PORT", 8080)), use_waitress=True
    )

When I run gunicorn to run dashboard.py using the code below:
gunicorn --bind 127.0.0.1:8080 --chdir ~/.../src dashboard:dashboard --timeout 0, I got an error message saying:

Failed to find attribute 'dashboard' in 'dashboard'.

If I remove the if __name__ == "__main__":, then the gunicorn works.

Why is that so?

How do I use the gunicorn command if I want to keep the if __name__ == "__main__":?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2025-02-08 09:20:24

from a.settings import (
        BLOB_DASHBOARD_CONFIG,
        BUCKET_NAME
    )

def run_explainer_dashboard(
    bucket_name: str,
    blob_dashboard_config: str,
    explainer_path: Union[str, "PathLike[str]"]
) -> ExplainerDashboard:
    ...
    return dashboard

dashboard = run_explainer_dashboard(
        bucket_name=BUCKET_NAME,
        blob_dashboard_config='dashboard.yaml',
        explainer_path="...",
    )

if __name__ == "__main__":
    dashboard.run(
        host="0.0.0.0", port=int(os.environ.get("PORT", 8080)), use_waitress=True
    )

from a.settings import (
        BLOB_DASHBOARD_CONFIG,
        BUCKET_NAME
    )

def run_explainer_dashboard(
    bucket_name: str,
    blob_dashboard_config: str,
    explainer_path: Union[str, "PathLike[str]"]
) -> ExplainerDashboard:
    ...
    return dashboard

dashboard = run_explainer_dashboard(
        bucket_name=BUCKET_NAME,
        blob_dashboard_config='dashboard.yaml',
        explainer_path="...",
    )

if __name__ == "__main__":
    dashboard.run(
        host="0.0.0.0", port=int(os.environ.get("PORT", 8080)), use_waitress=True
    )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文