Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127371 Avoid unbounded growth SpooledTempfile.writelines #127372

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bertptrs
Copy link

@bertptrs bertptrs commented Nov 28, 2024

By checking after every line whether we've rolled over, we ensure that internal buffer doesn't grow too far beyond the expected bounds (at most one line).

To avoid a performance regression, I opted to introduce several fast-paths: if the SpooledTemplFile has already been rolled over to disk, or if it never will because the size is unbounded, the implementation delegates directly to the underlying file object.

Copy link

cpython-cla-bot bot commented Nov 28, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Nov 28, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@tomasr8 tomasr8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think this also needs a test :)

Lib/tempfile.py Outdated Show resolved Hide resolved
@bertptrs
Copy link
Author

Thanks for the review! Addressed your comments and added a simple test.

@tomasr8
Copy link
Member

tomasr8 commented Nov 29, 2024

Thanks! Please avoid force pushing if possible, it makes it more difficult to see what the latest changes are 🙂

As the bot said, you'll also need to sign the Contributor License Agreement.

Lib/test/test_tempfile.py Show resolved Hide resolved
Lib/tempfile.py Show resolved Hide resolved
@bertptrs
Copy link
Author

I think it should be good like this, then. Note: I'm aware of the failing CI test for my news entry, but I don't know what's wrong about the way I linked the method. Could you help me with that?

@tomasr8
Copy link
Member

tomasr8 commented Nov 30, 2024

I think it should be good like this, then. Note: I'm aware of the failing CI test for my news entry, but I don't know what's wrong about the way I linked the method. Could you help me with that?

I think that's because the method is not documented so there is nothing to link to. IIRC ! should fix it, i.e.:

:meth:`!tempfile.SpooledTemporaryFile.writelines`

Copy link
Member

@tomasr8 tomasr8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants