Skip to content

Commit

Permalink
fix: make asyncio cancellation handling compatible with 3.10 (langflo…
Browse files Browse the repository at this point in the history
…w-ai#4303)

Fix asyncio cancellation handling for Python 3.11 compatibility

Co-authored-by: Christophe Bornet <[email protected]>
  • Loading branch information
2 people authored and diogocabral committed Nov 26, 2024
1 parent c1be1f5 commit 6ecf120
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/base/langflow/services/telemetry/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import os
import platform
import sys
from datetime import datetime, timezone
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6ecf120

Please sign in to comment.