From 1402e79372b772ef1f66bf03972aee865de4b6d8 Mon Sep 17 00:00:00 2001 From: shenchucheng Date: Wed, 23 Oct 2024 21:41:41 +0800 Subject: [PATCH] stop stream report if CancelledError --- metagpt/utils/report.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metagpt/utils/report.py b/metagpt/utils/report.py index 427f401ab..0ae19beba 100644 --- a/metagpt/utils/report.py +++ b/metagpt/utils/report.py @@ -165,9 +165,9 @@ class ResourceReporter(BaseModel): self._llm_task = asyncio.create_task(self._llm_stream_report(queue)) return self - async def __aexit__(self, *args, **kwargs): + async def __aexit__(self, exc_type, exc_value, exc_tb): """Exit the asynchronous streaming callback context.""" - if self.enable_llm_stream: + if self.enable_llm_stream and exc_type != asyncio.CancelledError: await get_llm_stream_queue().put(None) await self._llm_task self._llm_task = None