pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/encode/httpx/pull/3777

m/assets/global-a40b6ece39d70d4a.css" /> Add real async iterator for ByteStreams by akx · Pull Request #3777 · encode/httpx · GitHub
Skip to content

Add real async iterator for ByteStreams#3777

Open
akx wants to merge 1 commit intoencode:masterfrom
akx:trio-bytestream-timeout
Open

Add real async iterator for ByteStreams#3777
akx wants to merge 1 commit intoencode:masterfrom
akx:trio-bytestream-timeout

Conversation

@akx
Copy link
Copy Markdown

@akx akx commented Feb 24, 2026

Summary

Previously, __aiter__ was implemented as a generator function, and as such could get garbage collected when not completely exhausted in a way that has (recent versions of) trio complaining:

$ uv pip list | grep io
[... snip ...]
Package                    Version
anyio                      4.12.1
trio                       0.31.0
[... snip ...]
$ uv run pytest tests/ -k test_write_timeout[trio]
[... snip ...]
E ResourceWarning: Async generator 'httpx._content.ByteStream.__aiter__' was garbage collected before it had been exhausted. Surround its use in 'async with aclosing(...):' to ensure that it gets cleaned up as soon as you're done using it.

The above exception was the direct cause of the following exception:

E pytest.PytestUnraisableExceptionWarning: Exception ignored in: <async_generator object ByteStream.__aiter__ at 0x1075593c0>
[... snip ...]

Using a real, if trivial, object to do this causes less complaints.

Fixes #3686
Closes #3700 (fix for the same issue)

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
    • Retained pristine test coverage to check that the iterator does indeed adhere to the iterator protocol by returning itself when iterated upon.
  • I've updated the documentation accordingly.
    • No documentation changes required.

Previously, `__aiter__` was implemented as a generator function,
and as such could get garbage collected when not completely exhausted
in a way that has recent versions of `trio` complaining.

Using a real, if trivial, object to do this causes less complaints.

Fixes #3686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_write_timeout(trio) is failing on python3.14

1 participant

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy