Skip to content

Document cleaning up streaming responses without block usage - #840

Closed
florimondmanca wants to merge 2 commits into
masterfrom
non-context-managed-streaming
Closed

florimondmanca wants to merge 2 commits into
masterfrom
non-context-managed-streaming

Conversation

@florimondmanca

Copy link
Copy Markdown
Contributor

Fixes #830

Update the documentation on streaming responses (both in the sync and async cases) to indicate how users can clean use the .stream() context manager when block usage via with ... is not possible.

@florimondmanca florimondmanca added the docs Changes to the documentation label Mar 1, 2020
@lovelydinosaur

Copy link
Copy Markdown
Member

I think using AsyncExitStack here is a bit of a hacky work around.

We really want to stear folks away from using stream without a context manager wherever possible, but I'd be okay with us explaining why we do that, but documenting how to do it in the cases where it really is needed. For example...

request = client.build_request(...)
response = client.send(..., stream=True)
try:
    ...
finally:
    response.close()

@florimondmanca

Copy link
Copy Markdown
Contributor Author

Closing for now, will need to take another shot at this. :-)

@florimondmanca
florimondmanca deleted the non-context-managed-streaming branch March 16, 2020 21:35
Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
* Fix synchronous TLS-in-TLS

* changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Changes to the documentation

Development

Successfully merging this pull request may close these issues.

How about provide non-contextmanager api for stream?

2 participants