tempfile.SpooledTemporaryFile function operates exactly as
except that data is spooled in memory until the file size exceeds the parameter
max_size, or until the file’s
fileno() method is called, at which point the contents
are written to disk and operation proceeds as with
The resulting file has one additional method,
rollover(), which causes the file to roll
over to an on-disk file regardless of its size.
Via docs.python.org .