[Tutor] Making a Primary Number List generator

eryksun eryksun at gmail.com
Thu May 16 17:21:04 CEST 2013


On Thu, May 16, 2013 at 1:42 AM, eryksun <eryksun at gmail.com> wrote:
> On the other hand a BufferedWriter will buffer the remaining 3000
> bytes that can't be written. You won't find out until an exception is
> raised when the file is closed:

Actually it was buffering all 4000 bytes. I forgot about the fast path
that initially fills the buffer. The default buffer size is 4 KiB to
match the block size on my ext4 file system. So if I limit file size
to 1000 bytes, I can 'write' 5096 bytes before it raises an exception:

    >>> resource.setrlimit(resource.RLIMIT_FSIZE, (1000, -1))
    >>> f = open('temp.bin', 'wb')
    >>> f.write(b'spam'*1274)
    5096
    >>> f.write(b's')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno 27] File too large


More information about the Tutor mailing list