File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1775,3 +1775,20 @@ async def aclose(self) -> None:
17751775 await self ._async_httpx_client .aclose ()
17761776 if self ._aiohttp_session :
17771777 await self ._aiohttp_session .close ()
1778+
1779+ def __del__ (self ) -> None :
1780+ """Closes the API client when the object is garbage collected.
1781+
1782+ ADK uses this client so cannot rely on the genai.[Async]Client.__del__
1783+ for cleanup.
1784+ """
1785+
1786+ try :
1787+ self .close ()
1788+ except Exception : # pylint: disable=broad-except
1789+ pass
1790+
1791+ try :
1792+ asyncio .get_running_loop ().create_task (self .aclose ())
1793+ except Exception : # pylint: disable=broad-except
1794+ pass
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414#
1515
16+ import asyncio
1617import os
1718from types import TracebackType
1819from typing import Optional , Union
@@ -125,7 +126,6 @@ async def __aexit__(
125126 await self .aclose ()
126127
127128 def __del__ (self ) -> None :
128- import asyncio
129129 try :
130130 asyncio .get_running_loop ().create_task (self .aclose ())
131131 except Exception :
You can’t perform that action at this time.
0 commit comments