Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/openai/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ async def close(self) -> None:
"""
await self.response.aclose()

async def aclose(self) -> None:
"""
Async close method - alias for close() to support standard async cleanup protocol.

Used by asyncio, contextlib.aclosing(), httpx, anyio, and instrumentation libraries.
Comment on lines +241 to +245

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add aclose() to the helper async stream wrappers

This only makes the low-level AsyncStream compatible with contextlib.aclosing() / tracers that await obj.aclose(). The public helper entry points still hand callers wrapper objects with close() but no aclose()AsyncChatCompletionStream (src/openai/lib/streaming/chat/_completions.py:208), AsyncResponseStream (src/openai/lib/streaming/responses/_responses.py:172), and AsyncAssistantEventHandler (src/openai/lib/streaming/_assistants.py:505). Since client.chat.completions.stream(...) and client.responses.stream(...) return those wrappers via their managers, code that switches to contextlib.aclosing(stream) or instrumentation that unconditionally calls await stream.aclose() will still fail with AttributeError on those higher-level streaming APIs.

Useful? React with 👍 / 👎.

"""
await self.close()


class ServerSentEvent:
def __init__(
Expand Down