Python Filling Up Disk <p>I need to setup some test conditions to simulate a filled up disk. I created the following to simply write garbage to the disk:</p> <pre><code>#!/usr/bin/python import os import sys import mmap def freespace(p): """ Returns the number of free bytes on the drive that ``p`` is on """ s = os.statvfs(p) return s.f_bsize * s.f_bavail if __name__ == '__main__': drive_path = sys.argv[1] output_path = sys.argv[2] output_file = open(output_path, 'w') while freespace(drive_path) &gt; 0: output_file.write("!") print freespace(drive_path) output_file.flush() output_file.close() </code></pre> <p>As far as I can tell by looking at the return value from freespace, the write method does not write the file to until it is closed, thereby making the while condition invalid.</p> <p>Is there a way I can write the data directly to the file? Or another solution perhaps?</p>