Skip to content

Commit e556364

Browse files
Adding force_cancel
1 parent 0ecfa82 commit e556364

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/pipecat/pipeline/task.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,20 @@ async def cancel(self):
383383
"""Stops the running pipeline immediately."""
384384
await self._cancel()
385385

386+
async def force_cancel(self):
387+
"""Forcefully cancel the task and any running subtasks."""
388+
logger.debug(f"Force canceling task {self} triggered")
389+
try:
390+
await self.cancel()
391+
except Exception as e:
392+
logger.warning(f"Error calling pipecat task cancel {self}: {e}")
393+
394+
for task in self._task_manager.current_tasks():
395+
try:
396+
await self._task_manager.cancel_task(task)
397+
except Exception as e:
398+
logger.warning(f"Error canceling task {self}: {e}")
399+
386400
async def run(self, params: PipelineTaskParams):
387401
"""Starts and manages the pipeline execution until completion or cancellation."""
388402
if self.has_finished():

0 commit comments

Comments
 (0)