From 85a651cc1495a91639371d445001b1f30b01d0aa Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 28 Oct 2024 13:17:08 -0300 Subject: [PATCH] Fix asyncio cancellation handling for Python 3.11 compatibility --- src/backend/base/langflow/services/telemetry/service.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/services/telemetry/service.py b/src/backend/base/langflow/services/telemetry/service.py index 0c43cee96ceb..8823e2dbeecd 100644 --- a/src/backend/base/langflow/services/telemetry/service.py +++ b/src/backend/base/langflow/services/telemetry/service.py @@ -3,6 +3,7 @@ import asyncio import os import platform +import sys from datetime import datetime, timezone from typing import TYPE_CHECKING @@ -136,7 +137,10 @@ async def _cancel_task(self, task: asyncio.Task, cancel_msg: str) -> None: await task except asyncio.CancelledError: current_task = asyncio.current_task() - if current_task and current_task.cancelling() > 0: + if sys.version_info >= (3, 11): + if current_task and current_task.cancelling() > 0: + raise + elif current_task and hasattr(current_task, "_must_cancel") and current_task._must_cancel: raise async def stop(self) -> None: