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

如何排查Python Azure Function的“未处理异常”及主机Shutdown问题

Azure Function Python运行时主机Shutdown问题排查流程

1. 扩展日志查询范围,覆盖更多维度

仅查询traces表不足以定位完整原因,需联合多日志表排查shutdown前后的关键事件:

union traces, requests, functionAppLogs, hostLogs
| where timestamp between (todatetime('2023-04-18T06:00:00') .. todatetime('2023-04-18T09:00:00'))
| where operationName == "FunctionAppShutdown" 
   or message contains "shutdown" 
   or message contains "host stopping"
   or message contains "recycling"
| order by timestamp asc

重点关注shutdown时间点前的错误日志、资源超限提示、平台触发的回收指令。

2. 检查资源使用与限制触发的回收

  • 登录Azure门户,进入函数应用的指标页面,查看CPU使用率、内存工作集、磁盘可用空间在08:30-08:40时间段的波动,确认是否因资源超限触发主机回收。
  • 若使用消费计划,检查是否因闲置超时(默认10分钟无请求)触发自动回收;若使用专用计划,查看应用池的回收配置(如固定时间、内存阈值)。

3. 排查部署与配置变更

  • 查看函数应用部署中心的部署记录,确认07:23-08:33时间段内是否有代码部署、依赖包更新操作。
  • 进入配置页面,查看应用设置、连接字符串的修改历史,排查是否有配置变更导致运行异常。

4. 核查平台级事件与维护

  • 查看Azure门户的服务健康页面,确认函数应用所在区域在故障时间段是否有平台维护、节点故障通知。
  • 查询活动日志,排查是否有平台触发的资源操作:
ActivityLogs
| where ResourceGroup == "<你的资源组名称>"
| where Resource == "<你的函数应用名称>"
| where timestamp between (todatetime('2023-04-18T06:00:00') .. todatetime('2023-04-18T09:00:00'))
| order by timestamp asc

5. 分析Python运行时特定问题

针对Python函数,重点排查运行时层面的异常:

functionAppLogs
| where timestamp between (todatetime('2023-04-18T06:00:00') .. todatetime('2023-04-18T09:00:00'))
| where message contains "Exception" 
   or message contains "Error" 
   or message contains "Crash"
| order by timestamp asc

检查是否有未处理的异常、第三方依赖崩溃、内存泄漏等导致主机进程被终止。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 08:22:59