You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure App Service中启动Python Gradio应用失败求助

问题描述

已成功部署Azure App Service,但无法启动简单的Gradio应用。微软文档提到,未基于Gunicorn运行的Python框架需创建自定义启动命令。尝试在应用配置的启动命令字段中添加python app.py,但容器启动失败,错误日志如下:

2023-09-06T08:34:02.022Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 138.7764496 sec
2023-09-06T08:34:17.097Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 153.8518121 sec
2023-09-06T08:34:33.792Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 170.5465454 sec
2023-09-06T08:34:48.868Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 185.6226552 sec
2023-09-06T08:35:03.946Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 200.7001212 sec
2023-09-06T08:35:19.016Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 215.7710773 sec
2023-09-06T08:35:34.091Z INFO  - Waiting for response to warmup request for container whatschatgui_0_672c2d81. Elapsed time = 230.8458043 sec
2023-09-06T08:35:34.098Z ERROR - Container whatschatgui_0_672c2d81 for site whatschatgui did not start within expected time limit. Elapsed time = 230.8530481 sec
2023-09-06T08:35:34.115Z ERROR - Container whatschatgui_0_672c2d81 didn't respond to HTTP pings on port: 8000, failing site start. See container logs for debugging.
2023-09-06T08:35:36.786Z INFO  - Stopping site whatschatgui because it failed during startup.
解决思路
  • 确认Gradio监听端口:Azure App Service默认向端口8000发送健康检查请求,检查你的Gradio应用是否配置监听该端口。在app.py中启动Gradio时需指定端口为8000,示例代码:
    gr.Interface(...).launch(server_port=8000)
    
  • 用Gunicorn适配启动:实际用Gunicorn启动Gradio更适配Azure环境,修改启动命令为:
    gunicorn --bind=0.0.0.0:8000 app:app
    
    注意app:app指Python文件名为app.py且Gradio的Interface对象赋值给变量app,若变量名不同需对应修改,比如app:demo。
  • 检查依赖完整性:确保requirements.txt包含gradio和gunicorn(若用Gunicorn),确认部署时依赖已正确安装。
  • 查看容器详细日志:进入Azure门户的App Service资源,查看容器标准输出日志,获取Gradio启动时的具体报错(如端口占用、依赖缺失等)。
  • 确认启动命令路径:若app.py不在默认工作目录,启动命令需指定完整路径,比如python /home/site/wwwroot/app.py。

内容的提问来源于stack exchange,提问作者felfel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 12:35:15