Skip to content

Commit ef911ff

Browse files
committed
add is_closed checks before closing pooled clients
1 parent 2f1e263 commit ef911ff

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

src/bubble_data_api_client/pool.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ async def close_clients() -> None:
8989
]
9090

9191
for client in clients_to_close:
92-
try:
93-
await client.aclose()
94-
except Exception:
95-
pass # best-effort cleanup, continue with remaining clients
92+
if not client.is_closed:
93+
try:
94+
await client.aclose()
95+
except Exception:
96+
pass # best-effort cleanup, continue with remaining clients
9697

9798

9899
@asynccontextmanager
@@ -126,19 +127,21 @@ def _atexit_cleanup() -> None:
126127
if running_loop is not None and running_loop.is_running():
127128
# edge case: event loop still running, schedule cleanup with timeout
128129
for client in clients_to_close:
129-
future = asyncio.run_coroutine_threadsafe(client.aclose(), running_loop)
130-
try:
131-
future.result(timeout=5.0)
132-
except Exception:
133-
pass
130+
if not client.is_closed:
131+
try:
132+
future = asyncio.run_coroutine_threadsafe(client.aclose(), running_loop)
133+
future.result(timeout=5.0)
134+
except Exception:
135+
pass
134136
else:
135137
# no running loop, create one and close all clients
136138
async def _close_all() -> None:
137139
for client in clients_to_close:
138-
try:
139-
await client.aclose()
140-
except Exception:
141-
pass
140+
if not client.is_closed:
141+
try:
142+
await client.aclose()
143+
except Exception:
144+
pass
142145

143146
try:
144147
asyncio.run(_close_all())

0 commit comments

Comments
 (0)