Skip to content

Commit f3e53c8

Browse files
committed
fix: Added missing background task cleanup in _cleanup_async_resources method.
1 parent ed3e9b8 commit f3e53c8

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

sdk/python/agentfield/agent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4415,6 +4415,20 @@ async def _cleanup_async_resources(self) -> None:
44154415
if self.dev_mode:
44164416
log_debug(f"Error cleaning up AsyncExecutionManager: {e}")
44174417

4418+
if self._background_tasks:
4419+
try:
4420+
await asyncio.wait_for(
4421+
asyncio.gather(*self._background_tasks, return_exceptions=True),
4422+
timeout = 5
4423+
)
4424+
if self.dev_mode:
4425+
log_debug("Background tasks are cleaned up")
4426+
except Exception as e:
4427+
if self.dev_mode:
4428+
log_debug(f"Error cleaning up background tasks: {e}")
4429+
finally:
4430+
self._background_tasks.clear()
4431+
44184432
if getattr(self, "client", None) is not None:
44194433
try:
44204434
await self.client.aclose()

0 commit comments

Comments
 (0)