Chatbot example: clean up servers in correct order (#353)

This commit is contained in:
Clare Liguori 2025-05-23 03:30:50 -07:00 • committed by GitHub
commit 4cd4fe006c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -284,12 +284,9 @@ class ChatSession:
async def cleanup_servers(self) -> None:
"""Clean up all servers properly."""
cleanup_tasks = [
asyncio.create_task(server.cleanup()) for server in self.servers
]
if cleanup_tasks:
for server in reversed(self.servers):
try:
await asyncio.gather(*cleanup_tasks, return_exceptions=True)
await server.cleanup()
except Exception as e:
logging.warning(f"Warning during final cleanup: {e}")