DailyTransport: handle future cancellation

This commit is contained in:
Aleix Conchillo Flaqué
2025-08-06 23:01:41 -07:00
parent c97643c797
commit 86c6141580
2 changed files with 11 additions and 4 deletions

View File

@@ -81,6 +81,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed a `DailyTransport` issue that would result in an unhandled
`concurrent.futures.CancelledError` when a future is cancelled.
- Fixed a `RivaSTTService` issue that would result in an unhandled - Fixed a `RivaSTTService` issue that would result in an unhandled
`concurrent.futures.CancelledError` when a future is cancelled when reading `concurrent.futures.CancelledError` when a future is cancelled when reading
from the audio chunks from the incoming audio stream. from the audio chunks from the incoming audio stream.

View File

@@ -13,6 +13,7 @@ real-time communication features.
import asyncio import asyncio
import time import time
from concurrent.futures import CancelledError as FuturesCancelledError
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Awaitable, Callable, Dict, Mapping, Optional from typing import Any, Awaitable, Callable, Dict, Mapping, Optional
@@ -1320,10 +1321,13 @@ class DailyTransportClient(EventHandler):
def _call_async_callback(self, queue: asyncio.Queue, callback, *args): def _call_async_callback(self, queue: asyncio.Queue, callback, *args):
"""Queue a callback for async execution on the event loop.""" """Queue a callback for async execution on the event loop."""
future = asyncio.run_coroutine_threadsafe( try:
queue.put((callback, *args)), self._get_event_loop() future = asyncio.run_coroutine_threadsafe(
) queue.put((callback, *args)), self._get_event_loop()
future.result() )
future.result()
except FuturesCancelledError:
pass
async def _callback_task_handler(self, queue: asyncio.Queue): async def _callback_task_handler(self, queue: asyncio.Queue):
"""Handle queued callbacks from the specified queue.""" """Handle queued callbacks from the specified queue."""