Skip to content

Commit 2d7b697

Browse files
fix(client): close streams without requiring full consumption
1 parent 95f2d67 commit 2d7b697

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/perplexity/_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
if sse.event is None:
7777
yield process_data(data=sse.json(), 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
@@ -159,9 +158,8 @@ async def __stream__(self) -> AsyncIterator[_T]:
159158
if sse.event is None:
160159
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
161160

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

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

0 commit comments

Comments
 (0)