Unbounded growth in SpooledTemporaryFile.writelines()
#127371
Labels
type-bug
An unexpected behavior, bug, or error
SpooledTemporaryFile.writelines()
#127371
Bug report
Bug description:
SpooledTemporaryFile
provides a temporary file backed by a buffer in memory that spills over to disk when it gets too large. However, thewritelines()
method only checks whether it should roll over after the entire lines iterator is exhausted. This causes unexpectedly high memory use when feeding it large iterators.With the above code, one might expect that the buffer doesn't grow (much) past 1024 bytes, but it grows to almost three times that size before finally rolling over.
CPython versions tested on:
3.12, 3.13, CPython main branch
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: