From 6bca8396d37d555de47a73506de3e4ecda52d0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 24 Jan 2025 19:29:08 -0800 Subject: [PATCH] utils: error if we try to cancel the same task multiple times --- src/pipecat/utils/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pipecat/utils/utils.py b/src/pipecat/utils/utils.py index 6a708843d..045308c57 100644 --- a/src/pipecat/utils/utils.py +++ b/src/pipecat/utils/utils.py @@ -74,7 +74,10 @@ async def cancel_task(task: asyncio.Task, timeout: Optional[float] = None): except asyncio.CancelledError: # Here are sure the task is cancelled properly. logger.trace(f"{name}: task cancelled") - _TASKS.remove(task) + try: + _TASKS.remove(task) + except KeyError as e: + logger.error(f"{name}: error removing task (already removed?): {e}") except Exception as e: logger.exception(f"{name}: unexpected exception while cancelling task: {e}")