PipelineTask: check if pipeline has already been cancelled

This commit is contained in:
Aleix Conchillo Flaqué
2025-05-24 21:01:23 -07:00
parent 2e57bb74d2
commit 4eed335bc7
2 changed files with 12 additions and 7 deletions

View File

@@ -89,6 +89,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Check if `PipelineTask` has already been cancelled.
- Don't raise an exception if event handler is not registered. - Don't raise an exception if event handler is not registered.
- Upgraded `deepgram-sdk` to 4.1.0. - Upgraded `deepgram-sdk` to 4.1.0.

View File

@@ -236,6 +236,7 @@ class PipelineTask(BaseTask):
) )
observers.append(self._turn_trace_observer) observers.append(self._turn_trace_observer)
self._finished = False self._finished = False
self._cancelled = False
# This queue receives frames coming from the pipeline upstream. # This queue receives frames coming from the pipeline upstream.
self._up_queue = asyncio.Queue() self._up_queue = asyncio.Queue()
@@ -346,7 +347,6 @@ class PipelineTask(BaseTask):
async def cancel(self): async def cancel(self):
"""Stops the running pipeline immediately.""" """Stops the running pipeline immediately."""
logger.debug(f"Canceling pipeline task {self}")
await self._cancel() await self._cancel()
async def run(self): async def run(self):
@@ -406,6 +406,9 @@ class PipelineTask(BaseTask):
await self.queue_frame(frame) await self.queue_frame(frame)
async def _cancel(self): async def _cancel(self):
if not self._cancelled:
logger.debug(f"Canceling pipeline task {self}")
self._cancelled = True
# Make sure everything is cleaned up downstream. This is sent # Make sure everything is cleaned up downstream. This is sent
# out-of-band from the main streaming task which is what we want since # out-of-band from the main streaming task which is what we want since
# we want to cancel right away. # we want to cancel right away.