Skip to content

Commit 538c755

Browse files
Jeff Scuddercopybara-github
authored andcommitted
fix: Resolve potential mem leak on deletion of Client when using async
PiperOrigin-RevId: 812993926
1 parent 1692f23 commit 538c755

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

google/genai/_api_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def __del__(self) -> None:
528528
except Exception:
529529
pass
530530
try:
531-
asyncio.get_running_loop().create_task(self.aclose())
531+
asyncio.get_running_loop().run_until_complete(self.aclose())
532532
except Exception:
533533
pass
534534

@@ -1789,6 +1789,7 @@ def __del__(self) -> None:
17891789
pass
17901790

17911791
try:
1792-
asyncio.get_running_loop().create_task(self.aclose())
1792+
asyncio.get_running_loop().run_until_complete(self.aclose())
17931793
except Exception: # pylint: disable=broad-except
1794-
pass
1794+
pass
1795+

google/genai/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async def __aexit__(
127127

128128
def __del__(self) -> None:
129129
try:
130-
asyncio.get_running_loop().create_task(self.aclose())
130+
asyncio.get_running_loop().run_until_complete(self.aclose())
131131
except Exception:
132132
pass
133133

@@ -398,3 +398,4 @@ def __exit__(
398398

399399
def __del__(self) -> None:
400400
self.close()
401+

0 commit comments

Comments
 (0)