Skip to content

Commit 31e3903

Browse files
fix(client): close streams without requiring full consumption
1 parent f2ef07d commit 31e3903

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/writerai/_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
response=self.response,
7777
)
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
response=self.response,
160159
)
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)