Merge pull request #2729 from pipecat-ai/aleix/frame-processor-cancel-default-timeout

FrameProcessor: timeout when cancelling tasks
This commit is contained in:
Aleix Conchillo Flaqué
2025-09-24 10:55:52 -07:00
committed by GitHub
2 changed files with 11 additions and 1 deletions

View File

@@ -455,9 +455,13 @@ class FrameProcessor(BaseObject):
name = f"{self}::{coroutine.cr_code.co_name}"
return self.task_manager.create_task(coroutine, name)
async def cancel_task(self, task: asyncio.Task, timeout: Optional[float] = None):
async def cancel_task(self, task: asyncio.Task, timeout: Optional[float] = 1.0):
"""Cancel a task managed by this processor.
A default timeout if 1 second is used in order to avoid potential
freezes caused by certain libraries that swallow
`asyncio.CancelledError`.
Args:
task: The task to cancel.
timeout: Optional timeout for task cancellation.