尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

【Azure Function App】升级 Python 运行时 3.9 到3.10 后遇见的问题

【Azure Function App】升级 Python 运行时 3.9 到3.10 后遇见的问题 问题描述Azure Function 原来运行在 Python 3.9。由于 Python 3.9 即将停止维护需要升级到 Python 3.10。第一次升级时只是在 Function App 页面中进入Settings → Configuration → General settings将 Python 版本从 3.9 修改为 3.10。Function App 表面上可以正常启动但绑定的 Service Bus topic-subscription 消息不再被正常消费。观察到的主要错误如下Loading function failed. ExceptionType: System.TimeoutException Timeout value of 00:30:00 exceeded by function Functions.func1 Executed Functions.func1 (Failed, Duration1800022ms) Message processing error (ActionProcessMessageCallback, EntityPathtopic-name/Subscriptions/subscription-name)后台日志中还可以看到 Python Worker 被强制终止The process with PID XXXX (language worker) was forcefully terminated. Exit code: 137 (SIGKILL)之后重新部署了新的 package但消息仍然无法消费。这次错误变成了函数加载阶段立即失败[Error] Executed Functions.func1 (Failed, Duration1ms) Exception: AttributeError: attribute __default__ of typing.ParamSpec objects is not writable堆栈中可以看到错误发生在导入azure.storage.blob的过程中最终落到typing_extensions.pyFile .../azure/storage/blob/_blob_client.py, line 22, in module from azure.core.tracing.decorator import distributed_trace File .../azure/core/tracing/decorator.py, line 37, in module P ParamSpec(P) File .../typing_extensions.py, line 1474, in _set_default type_param.__default__ None AttributeError: attribute __default__ of typing.ParamSpec objects is not writable问题解答这次问题主要分成两个阶段。1. 只修改 Function App 运行时版本依赖包没有重新构建第一个错误的重点是System.TimeoutException Duration1800022ms exit code 137 / SIGKILL这说明函数并不是业务代码执行慢而是在 Worker 加载函数时卡住最终被 Host 强制终止。常见原因是应用使用WEBSITE_RUN_FROM_PACKAGE方式部署zip 包中的 Python 依赖是在旧的 Python 3.9 环境下安装或编译的。只在 Portal 中把运行时改成 Python 3.10 后云端解释器变成了 3.10但包里的原生依赖仍可能是 3.9 的构建产物例如grpcio、protobuf、cryptography等从而导致函数加载异常或超时。建议处理方式在本地准备目标 Python 版本环境例如 Python 3.10。删除旧依赖包不复用 Python 3.9 环境下生成的 package。在 Python 3.10 环境下重新安装依赖pip install --upgrade pip pip install -r requirements.txt重新打包并部署。2.typing_extensions与实际 Python 运行时不兼容第二个错误的重点是AttributeError: attribute __default__ of typing.ParamSpec objects is not writable如果堆栈中出现类似下面的路径/azure-functions-host/workers/python/3.13/...说明当前实际运行环境可能涉及 Python 3.13。旧版typing_extensions与 Python 3.13 中typing.ParamSpec.__default__的行为不兼容可能在导入azure.storage.blob、azure.core.tracing.decorator等依赖时直接失败。建议处理方式在requirements.txt中显式指定较新的typing_extensions版本typing_extensions4.12.0重新安装依赖并重新打包pip install --upgrade pip pip install -r requirements.txt部署后检查 Function App 实际 Python 运行时版本确认它和预期一致。如果目标是 Python 3.10需要确认配置没有实际运行到 Python 3.13。再次验证函数是否可以正常加载以及 Service Bus topic-subscription 中的消息是否可以正常消费总结Azure Functions 升级 Python 运行时时不建议只在 Portal 中修改 Python 版本。更稳妥的顺序是准备目标 Python 版本环境 → 重新安装依赖 → 重新打包 → 部署到 Staging Slot 验证 → 确认实际运行时版本 → Swap 到生产环境这次排查中两个关键点分别是System.TimeoutException、Duration1800022ms、exit code 137优先检查是否复用了旧 Python 版本构建出来的依赖包。AttributeError: attribute __default__ of typing.ParamSpec objects is not writable优先检查typing_extensions版本以及实际运行的 Python 版本是否符合预期。参考资料更新 Azure Functions 中的语言堆叠版本 更新 Azure Functions 中的语言版本 | Azure Docsattribute __default__ of typing.ParamSpec objects is not writableon Python 3.13 :https://github.com/python/typing_extensions/issues/404
返回列表