Repository navigation
gh-159422: Always close GzipFile in __del__ even if the warning fails - #159423
Open
brittanyrey wants to merge 3 commits into
Open
brittanyrey wants to merge 3 commits into
brittanyrey wants to merge 3 commits into
Conversation
GzipFile.__del__ emits a ResourceWarning before closing the file. If emitting it raises, close() is skipped and the gzip trailer is never written, truncating the output. This happens at interpreter shutdown, when the function-level `import warnings` fails, and with -W error::ResourceWarning. Close the file in a finally block.
aisk
previously approved these changes
Oct 14, 2026
aisk
self-requested a review
October 14, 2026 16:51
aisk
dismissed
their stale review
October 14, 2026 16:52
Just found the newly added test fails on the free-threaded build
aisk
reviewed
Oct 14, 2026
The order of __del__ calls at interpreter shutdown is not deterministic on the free-threaded build, so make the warning raise directly.
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.
BUG: GzipFile.del emits a ResourceWarning before closing the file. If emitting it raises an exception,
close()is skipped and the gzip file left truncated and incomplete.FIX: Close the file in a finally block to ensure it always runs.
NEW TEST: The new test is load bearing, without the fix it fails with
EOFError: Compressed file ended before the end-of-stream marker was reached.