brief-vase-33757
07/28/2025, 10:38 AMtall-airline-16756
07/28/2025, 10:38 AMtall-airline-16756
07/28/2025, 10:39 AMasyncio.exceptions.CancelledError and TimeoutError. These exceptions typically occur in asynchronous operations when tasks are either cancelled or exceed their allowed execution time. Here are some steps to address these issues:
• Handling CancelledError:
◦ Ensure that cancellation is propagated correctly by re-raising the CancelledError unless specific cleanup is required.
◦ For long-running tasks, catch the exception and perform necessary cleanup before re-raising it. For example: except asyncio.CancelledError:
<http://logger.info|logger.info>("Task cancelled")
self._close_current_generation()
raise
• Handling TimeoutError:
◦ Convert generic timeouts to domain-specific errors for better error handling. For example: except asyncio.TimeoutError:
raise APITimeoutError() from None
◦ Log timeout events for debugging purposes and provide user-friendly fallback responses. For example: except TimeoutError:
yield "Sorry, I’m taking too long to respond. Please try again later."
return
• Best Practices:
◦ Always log cancellation and timeout events to aid in debugging.
◦ Use finally blocks for proper cleanup when handling cancellations.
◦ For RPC operations, ensure that exceptions are converted to specific RPC errors, such as RpcError with appropriate error codes.
If you need further assistance or specific guidance for your implementation, let me know.
Sources: examples/rpc.py | livekit-agents/livekit/agents/ipc/supervised_proc.py | External data and RAG | LiveKit Docs | server/chatgpt.py