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,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.
|
||||||
|
|||||||
Reference in New Issue
Block a user