ref: Use better task cancellation logic (#5397)
Use better task cancellation logic Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
70b4719def
commit
3454ede5a5
1 changed files with 5 additions and 10 deletions
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
|
@ -135,15 +134,11 @@ class TelemetryService(Service):
|
||||||
|
|
||||||
async def _cancel_task(self, task: asyncio.Task, cancel_msg: str) -> None:
|
async def _cancel_task(self, task: asyncio.Task, cancel_msg: str) -> None:
|
||||||
task.cancel(cancel_msg)
|
task.cancel(cancel_msg)
|
||||||
try:
|
await asyncio.wait([task])
|
||||||
await task
|
if not task.cancelled():
|
||||||
except asyncio.CancelledError:
|
exc = task.exception()
|
||||||
current_task = asyncio.current_task()
|
if exc is not None:
|
||||||
if sys.version_info >= (3, 11):
|
raise exc
|
||||||
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:
|
async def stop(self) -> None:
|
||||||
if self.do_not_track or self._stopping:
|
if self.do_not_track or self._stopping:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue