Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6132922

Browse files
fix(client): close streams without requiring full consumption
1 parent b16bf4e commit 6132922

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/openai/_streaming.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ def __stream__(self) -> Iterator[_T]:
9696

9797
yield process_data(data=data, cast_to=cast_to, response=response)
9898

99-
# Ensure the entire stream is consumed
100-
for _sse in iterator:
101-
...
99+
# As we might not fully consume the response stream, we need to close it explicitly
100+
response.close()
102101

103102
def __enter__(self) -> Self:
104103
return self
@@ -198,9 +197,8 @@ async def __stream__(self) -> AsyncIterator[_T]:
198197

199198
yield process_data(data=data, cast_to=cast_to, response=response)
200199

201-
# Ensure the entire stream is consumed
202-
async for _sse in iterator:
203-
...
200+
# As we might not fully consume the response stream, we need to close it explicitly
201+
await response.aclose()
204202

205203
async def __aenter__(self) -> Self:
206204
return self

0 commit comments

Comments
 (0)