This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Write to /dev/full does not raise IOError
Type: Stage:
Components: IO Versions: Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: mvyskocil, vstinner
Priority: normal Keywords:

Created on 2011-01-03 14:26 by mvyskocil, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg125175 - (view) Author: Michal Vyskocil (mvyskocil) Date: 2011-01-03 14:26
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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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
msg125177 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-01-03 14:41
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.
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 55024
2011-01-03 14:41:45vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg125177

resolution: fixed
2011-01-03 14:26:43mvyskocilcreate