RivaSTTService: handle future cancellation

This commit is contained in:
Aleix Conchillo Flaqué
2025-08-06 22:56:08 -07:00
parent ad1841b739
commit 434d346079
2 changed files with 11 additions and 2 deletions

View File

@@ -81,6 +81,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed a `RivaSTTService` issue that would result in an unhandled
`concurrent.futures.CancelledError` when a future is cancelled when reading
from the audio chunks from the incoming audio stream.
- Fixed an issue in the `BaseOutputTransport`, mainly reproducible with - Fixed an issue in the `BaseOutputTransport`, mainly reproducible with
`FastAPIWebsocketOutputTransport` when the audio mixer was enabled, where the `FastAPIWebsocketOutputTransport` when the audio mixer was enabled, where the
loop could consume 100% CPU by continuously returning without delay, preventing loop could consume 100% CPU by continuously returning without delay, preventing

View File

@@ -7,6 +7,7 @@
"""NVIDIA Riva Speech-to-Text service implementations for real-time and batch transcription.""" """NVIDIA Riva Speech-to-Text service implementations for real-time and batch transcription."""
import asyncio import asyncio
from concurrent.futures import CancelledError as FuturesCancelledError
from typing import AsyncGenerator, List, Mapping, Optional from typing import AsyncGenerator, List, Mapping, Optional
from loguru import logger from loguru import logger
@@ -366,8 +367,12 @@ class RivaSTTService(STTService):
""" """
if not self._thread_running: if not self._thread_running:
raise StopIteration raise StopIteration
future = asyncio.run_coroutine_threadsafe(self._queue.get(), self.get_event_loop())
return future.result() try:
future = asyncio.run_coroutine_threadsafe(self._queue.get(), self.get_event_loop())
return future.result()
except FuturesCancelledError:
raise StopIteration
def __iter__(self): def __iter__(self):
"""Return iterator for audio chunk processing. """Return iterator for audio chunk processing.