Skip to content

Commit

Permalink
processors(frame_processors): add a try/except when cancelling tasks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aconchillo committed Dec 24, 2024
1 parent 082a3b0 commit d72a884
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pipecat/processors/frame_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,15 @@ def __create_push_task(self):
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
Expand Down

0 comments on commit d72a884

Please sign in to comment.