docs: port _closing comments from BaseOpenAILLMService
This commit is contained in:
committed by
Mark Backman
parent
0ae6a8b63a
commit
eb3affd45b
@@ -230,14 +230,22 @@ class OpenAIResponsesLLMService(LLMService):
|
|||||||
function_calls: Dict[str, Dict[str, str]] = {} # item_id -> {name, call_id, arguments}
|
function_calls: Dict[str, Dict[str, str]] = {} # item_id -> {name, call_id, arguments}
|
||||||
current_arguments: Dict[str, str] = {} # item_id -> accumulated arguments
|
current_arguments: Dict[str, str] = {} # item_id -> accumulated arguments
|
||||||
|
|
||||||
|
# Ensure stream and its async iterator are closed on cancellation/exception
|
||||||
|
# to prevent socket leaks and uvloop crashes. Closing the iterator first
|
||||||
|
# cascades cleanup through nested async generators (httpx/httpcore internals),
|
||||||
|
# preventing uvloop's broken asyncgen finalizer from firing on Python 3.12+
|
||||||
|
# (MagicStack/uvloop#699).
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def _closing(stream):
|
async def _closing(stream):
|
||||||
chunk_iter = stream.__aiter__()
|
chunk_iter = stream.__aiter__()
|
||||||
try:
|
try:
|
||||||
yield chunk_iter
|
yield chunk_iter
|
||||||
finally:
|
finally:
|
||||||
|
# Close the iterator first to cascade cleanup through
|
||||||
|
# nested async generators (httpx/httpcore internals).
|
||||||
if hasattr(chunk_iter, "aclose"):
|
if hasattr(chunk_iter, "aclose"):
|
||||||
await chunk_iter.aclose()
|
await chunk_iter.aclose()
|
||||||
|
# Then close the stream to release HTTP resources.
|
||||||
if hasattr(stream, "close"):
|
if hasattr(stream, "close"):
|
||||||
await stream.close()
|
await stream.close()
|
||||||
elif hasattr(stream, "aclose"):
|
elif hasattr(stream, "aclose"):
|
||||||
|
|||||||
Reference in New Issue
Block a user