PipelineTask: check if pipeline has already been cancelled
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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,12 +406,15 @@ class PipelineTask(BaseTask):
|
|||||||
await self.queue_frame(frame)
|
await self.queue_frame(frame)
|
||||||
|
|
||||||
async def _cancel(self):
|
async def _cancel(self):
|
||||||
# Make sure everything is cleaned up downstream. This is sent
|
if not self._cancelled:
|
||||||
# out-of-band from the main streaming task which is what we want since
|
logger.debug(f"Canceling pipeline task {self}")
|
||||||
# we want to cancel right away.
|
self._cancelled = True
|
||||||
await self._source.push_frame(CancelFrame())
|
# Make sure everything is cleaned up downstream. This is sent
|
||||||
# Only cancel the push task. Everything else will be cancelled in run().
|
# out-of-band from the main streaming task which is what we want since
|
||||||
await self._task_manager.cancel_task(self._process_push_task)
|
# we want to cancel right away.
|
||||||
|
await self._source.push_frame(CancelFrame())
|
||||||
|
# Only cancel the push task. Everything else will be cancelled in run().
|
||||||
|
await self._task_manager.cancel_task(self._process_push_task)
|
||||||
|
|
||||||
async def _create_tasks(self):
|
async def _create_tasks(self):
|
||||||
self._process_up_task = self._task_manager.create_task(
|
self._process_up_task = self._task_manager.create_task(
|
||||||
|
|||||||
Reference in New Issue
Block a user