Skip to content

Commit

Permalink
Use better task cancellation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Dec 24, 2024
1 parent b2e7476 commit ae9179e
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/backend/base/langflow/services/telemetry/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import os
import platform
import sys
from datetime import datetime, timezone
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -135,15 +134,11 @@ async def flush(self) -> None:

async def _cancel_task(self, task: asyncio.Task, cancel_msg: str) -> None:
task.cancel(cancel_msg)
try:
await task
except asyncio.CancelledError:
current_task = asyncio.current_task()
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
await asyncio.wait([task])
if not task.cancelled():
exc = task.exception()
if exc is not None:
raise exc

async def stop(self) -> None:
if self.do_not_track or self._stopping:
Expand Down

0 comments on commit ae9179e

Please sign in to comment.