From ba6e9ed9ad7ddcee9b1ee574b435c6d86b4261f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 23 Dec 2024 17:57:45 -0800 Subject: [PATCH] processors(frame_processors): add a try/except when cancelling tasks This seems necessary because of how pytest works. If a task is cancelled, pytest will know the task has been cancelled even if # `asyncio.CancelledError` is handled internally in the task. --- src/pipecat/processors/frame_processor.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pipecat/processors/frame_processor.py b/src/pipecat/processors/frame_processor.py index e3dfe0bce..521918b69 100644 --- a/src/pipecat/processors/frame_processor.py +++ b/src/pipecat/processors/frame_processor.py @@ -311,8 +311,15 @@ class FrameProcessor: self.__push_frame_task = self.get_event_loop().create_task(self.__push_frame_task_handler()) async def __cancel_push_task(self): - self.__push_frame_task.cancel() - await self.__push_frame_task + try: + self.__push_frame_task.cancel() + await self.__push_frame_task + except asyncio.CancelledError: + # TODO(aleix: Investigate why this is really needed. So far, this is + # necessary because of how pytest works. If a task is cancelled, + # pytest will know the task has been cancelled even if + # `asyncio.CancelledError` is handled internally in the task. + pass async def __push_frame_task_handler(self): running = True