Skip to content

Commit 33fe04b

Browse files
fix(client): close streams without requiring full consumption
1 parent db39cc6 commit 33fe04b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/gradient/_streaming.py

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

7777
yield process_data(data=data, cast_to=cast_to, response=response)
7878

79-
# Ensure the entire stream is consumed
80-
for _sse in iterator:
81-
...
79+
# As we might not fully consume the response stream, we need to close it explicitly
80+
response.close()
8281

8382
def __enter__(self) -> Self:
8483
return self
@@ -158,9 +157,8 @@ async def __stream__(self) -> AsyncIterator[_T]:
158157

159158
yield process_data(data=data, cast_to=cast_to, response=response)
160159

161-
# Ensure the entire stream is consumed
162-
async for _sse in iterator:
163-
...
160+
# As we might not fully consume the response stream, we need to close it explicitly
161+
await response.aclose()
164162

165163
async def __aenter__(self) -> Self:
166164
return self

0 commit comments

Comments
 (0)