gh-136059: docs: pathlib: Mention that iterdir() is surprisingly not streaming - #136060
Open
nh2 wants to merge 1 commit into
Open
gh-136059: docs: pathlib: Mention that iterdir() is surprisingly not streaming#136060nh2 wants to merge 1 commit into
nh2 wants to merge 1 commit into
Conversation
This undocumented gotcha can cause excessive memory usage
when "iterating" over very large directories.
This is because iterdir() does
entries = list(scandir_it)
Fixing (if at all desired) will likel need least significant amounts of
discussion and testing, so first document the behaviour.
| If the path is not a directory or otherwise inaccessible, :exc:`OSError` is | ||
| raised. | ||
|
|
||
| .. warning:: |
Member
There was a problem hiding this comment.
warning and even note directives attract too much attention. We usually avoid using them except in serious cases. Try also to shorten the text and don't describe the current behavior as a bug. For example, somethink like this:
"The contents of the directory are read in one go, but path objects are created during iteration. If you need to reduce latency for large directories, use :func:`os.scandir` instead."
|
This PR is stale because it has been open for 30 days with no activity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This undocumented gotcha can cause excessive memory usage when "iterating" over very large directories.
This is because iterdir() does
Fixing (if at all desired) will likel need least significant amounts of discussion and testing, so first document the behaviour.
See:
📚 Documentation preview 📚: https://cpython-previews--136060.org.readthedocs.build/