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: I/O error during one-liner gives no (!) diagnostic (and fails to return OS error status)
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: stdout error at interpreter shutdown fails to return OS error status
View: 5319
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, gvanrossum, mkc, pitrou, skrah
Priority: normal Keywords:

Created on 2009-02-19 17:50 by mkc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg82486 - (view) Author: Mike Coleman (mkc) Date: 2009-02-19 17:50
$ python3.0 -c 'print((1, 2, 3))' > /dev/full || echo error status
$

This command gives no indication whatsoever that anything has gone
wrong.  Following this with strace demonstrates that the interpreter is
in fact ignoring these errors:

2589  write(1, "(1, 2, 3)\n"..., 10)    = -1 ENOSPC (No space left on
device)
2589  rt_sigaction(SIGINT, {SIG_DFL}, {0x47aa49, [], SA_RESTORER,
0x7fd5aa9da080}, 8) = 0
2589  write(1, "(1, 2, 3)\n"..., 10)    = -1 ENOSPC (No space left on
device)
2589  write(1, "(1, 2, 3)\n"..., 10)    = -1 ENOSPC (No space left on
device)
2589  write(1, "(1, 2, 3)\n"..., 10)    = -1 ENOSPC (No space left on
device)
2589  exit_group(0)                     = ?
msg109754 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-09 15:41
Can anyone with a Linux box please check to see if this is still an issue.
msg109759 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-09 16:03
Yes, py3k r82745 still shows the problem
msg109767 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-07-09 16:39
Yes, it's an issue in py3k. Also, I prefer the behavior of 2.5, but
I'm not sure if that can be changed easily in 2.7.


$ python2.5 -c 'print((1, 2, 3))' > /dev/full
close failed: [Errno 28] No space left on device

$ python2.7 -c 'print((1, 2, 3))' > /dev/full
close failed in file object destructor:
Error in sys.excepthook:

Original exception was:


$ python3.2 -c 'print((1, 2, 3))' > /dev/full
$
msg109772 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-09 16:53
The issue is that when close() calls flush(), errors are silently discarded. I'm sure a similar issue was already filed, but could not find it.
msg109781 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-09 18:51
> The issue is that when close() calls flush(), errors are silently
> discarded

This has been fixed in 3.1 and 3.2:

$ ./python -c "with open('/dev/full', 'w') as f: print('a', file=f)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
IOError: [Errno 28] No space left on device

However, it seems sys.stdout has a different treatment:

$ ./python -c "print('a')" > /dev/full
$
msg109793 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-07-09 20:31
It looks like the error is cleared in Python/pythonrun.c, line 321:

    if (fout != NULL && fout != Py_None) {
        tmp = PyObject_CallMethod(fout, "flush", "");
        if (tmp == NULL)
            PyErr_Clear();
        else
            Py_DECREF(tmp);
    }


Not sure why it isn't handled before that.
msg110107 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-12 16:19
I agree that errors while flushing stdout shouldn't be silenced but instead reported (on stderr, obviously :-)). It is especially important when scripts are used for data processing.
I'd like to have Guido's opinion, though.
msg113338 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-08-08 22:06
Closing as a duplicate of issue 5319.
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49571
2010-08-08 22:06:04skrahsetstatus: open -> closed
resolution: duplicate
superseder: stdout error at interpreter shutdown fails to return OS error status
messages: + msg113338
2010-07-12 16:19:48pitrousetnosy: + gvanrossum
messages: + msg110107
2010-07-09 20:31:17skrahsetmessages: + msg109793
2010-07-09 18:51:17pitrousetmessages: + msg109781
2010-07-09 16:53:10amaury.forgeotdarcsetnosy: + pitrou
messages: + msg109772
2010-07-09 16:39:17skrahsetnosy: + skrah
messages: + msg109767
2010-07-09 16:03:07amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg109759
2010-07-09 15:41:34BreamoreBoysetnosy: + BreamoreBoy

messages: + msg109754
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 3.0
2009-02-19 17:50:03mkccreate