Feature or enhancement
Proposal:
This may indicate accidental data loss.
Ways to make sure all data is written:
- Use the file-like object as a “With Statement Context Manager”.
- Ensure
.close() is always called which flushes data before closing.
- If the underlying stream need to be kept open, use
.detach()
Since 3.12 flushing has been necessary in GzipFile (see gh-105808 which was a release blocker), this makes that more visible. Users have been encountering as they upgrade to 3.12 (ex. gh-129726).
There are a number of cases of unclosed file-like objects being deleted in CPython libraries and the test suite. This issue includes resolving those cases where the new ResourceWarning is emitted.
cc: @vstinner
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
#129726 (comment)
Linked PRs