为什么枪支未能在PY文件中找到属性?
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)