Issue 10815: Write to /dev/full does not raise IOError (original) (raw)

Write to /dev/full in python3 don't raise IOError. Python2 works as expected, the close call causes an IOError exception with no space left on device message.

$ python Python 2.7 (r27:82500, Aug 07 2010, 16:54:59) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information.

f = open('/dev/full', 'w') f.write('s') f.close() Traceback (most recent call last): File "", line 1, in IOError: [Errno 28] No space left on device

However using python3 I don't get an IOError after close $ python3 Python 3.1.2 (r312:79147, Nov 20 2010, 11:33:28) [GCC 4.5.1 20101001 [gcc-4_5-branch revision 164883]] on linux2 Type "help", "copyright", "credits" or "license" for more information.

f = open('/dev/full', 'w') f.write('s') 1 f.close()

The only one way how to raise IOError in python3 is call f.flush()

...

f.write('s') 1 f.flush() Traceback (most recent call last): File "", line 1, in IOError: [Errno 28] No space left on device

Documentation of io.IOBase.close() [1] said Flush and close this stream, so one should expect calls f.flush();f.close() will be the same as plain f.close().

[1] http://docs.python.org/py3k/library/io.html

This issue is fixed in Python 3.2 beta 2:

$ ./python

f=open("/dev/full", "wb") f.write(b'x') 1 f.close() IOError: [Errno 28] No space left on device ^D

sys:1: ResourceWarning: unclosed file <_io.BufferedWriter name='/dev/full'> sys:1: ResourceWarning: unclosed file <_io.FileIO name='/dev/full' mode='wb'>

If you would like to get the error earlier, disable the buffer (which is not completly possible for a text file, Python requires at least a line buffer).

Backport the fix to Python 3.1 is not a good idea because it may break programs using Python 3.1.