Skip to content

Commit 109b771

Browse files
fix(client): close streams without requiring full consumption
Co-Authored-By: fede-kamel
1 parent 2e2f663 commit 109b771

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/anthropic/_streaming.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ def __stream__(self) -> Iterator[_T]:
113113
response=self.response,
114114
)
115115

116-
# Ensure the entire stream is consumed
117-
for _sse in iterator:
118-
...
116+
# As we might not fully consume the response stream, we need to close it explicitly
117+
response.close()
119118

120119
def __enter__(self) -> Self:
121120
return self
@@ -231,9 +230,8 @@ async def __stream__(self) -> AsyncIterator[_T]:
231230
response=self.response,
232231
)
233232

234-
# Ensure the entire stream is consumed
235-
async for _sse in iterator:
236-
...
233+
# As we might not fully consume the response stream, we need to close it explicitly
234+
await response.aclose()
237235

238236
async def __aenter__(self) -> Self:
239237
return self

0 commit comments

Comments
 (0)