Skip to content

Commit 8be57fc

Browse files
author
Francisco
committed
fix(stream): explicitly close async generator in stream_chunks finally block — prevents Task destroyed RuntimeWarning from dangling aiter_bytes coroutines
1 parent e50575f commit 8be57fc

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/projectdavid/clients/synchronous_inference_wrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ async def _stream_chunks_async():
183183
LOG.error(f"[SyncStream] Streaming error: {exc}", exc_info=True)
184184
break
185185
finally:
186+
# Explicitly close the async generator to prevent
187+
# "Task was destroyed but it is pending" warnings from
188+
# dangling aiter_bytes coroutines.
189+
try:
190+
active_loop.run_until_complete(agen.aclose())
191+
except Exception: # nosec B110 — best-effort cleanup, failure is non-fatal
192+
pass
186193
if is_new_loop and active_loop:
187194
try:
188195
pending = asyncio.all_tasks(active_loop)

0 commit comments

Comments
 (0)