classification
Title: stdout error at interpreter shutdown fails to return OS error status
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, georg.brandl, mkc, pitrou, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2009-02-19 17:38 by mkc, last changed 2011-11-27 00:29 by Arfrever.

Files
File name Uploaded Description Edit
devfull.patch pitrou, 2010-08-04 23:35 review
Messages (7)
msg82482 - (view) Author: Mike Coleman (mkc) Date: 2009-02-19 17:37
$ python2.5 -c 'print((1, 2, 3))' > /dev/full || echo error status
close failed: [Errno 28] No space left on device
$

The above sequence should also output 'error status' before the next
prompt.  That is, python should not be returning EXIT_SUCCESS in this
situation.
msg82484 - (view) Author: Mike Coleman (mkc) Date: 2009-02-19 17:43
Oops, I should have used the old python print syntax.  Nonetheless, the
behavior is the same:

$ python2.5 -c 'print 1, 2, 3' > /dev/full || echo error status
close failed: [Errno 28] No space left on device
$
msg112342 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-01 15:06
Python 2.6, from #5320:

$ python2.6 -c 'print 1, 2, 3' > /dev/full || echo error status
close failed in file object destructor:
Error in sys.excepthook:

Original exception was:
$

Python 3.1 doesn't output anything and also doesn't set an error status.
msg112919 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-04 23:04
Georg, are you saying that there is or is not a problem with 2.6 (which is beyond non-critical bug fixes) and/or 3.1?
msg112923 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-04 23:35
Here is a possible patch for 3.x.
It doesn't change the return status of the process, though.
msg113330 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-08 21:40
I've committed the py3k fix in r83854 (3.1 in r83855).
As for 2.6/2.7, I've finally diagnosed the problem: 2.6 and upwards use PyErr_Print() in the file destructor, but the sys.stderr and sys.excepthook objects are already None at that time (because of interpreter shutdown). Therefore the error can't be printed out.
2.5 and earlier used a direct fprintf() of the errno code to stderr.

I propose to ignore the 2.6/2.7 issue of the error not being printed properly, since it only happens at shutdown with a misbehaving stdout, which is not very common.

As for the issue of the stdout error not being reported in the process return code, this would be possible in 3.x, although it would involve changing the signature of Py_Finalize() to include a return status (it currently returns void).
msg148423 - (view) Author: Roundup Robot (python-dev) Date: 2011-11-26 21:11
New changeset 150e096095e5 by Antoine Pitrou in branch '3.2':
Issue #13444: When stdout has been closed explicitly, we should not attempt to flush it at shutdown and print an error.
http://hg.python.org/cpython/rev/150e096095e5

New changeset 37300a1df7d7 by Antoine Pitrou in branch 'default':
Issue #13444: When stdout has been closed explicitly, we should not attempt to flush it at shutdown and print an error.
http://hg.python.org/cpython/rev/37300a1df7d7
History
Date User Action Args
2011-11-27 00:29:42Arfreversetnosy: + Arfrever
2011-11-26 21:11:58python-devsetnosy: + python-dev
messages: + msg148423
2010-08-08 22:06:04skrahlinkissue5321 superseder
2010-08-08 21:40:35pitrousettitle: I/O error during one-liner fails to return OS error status -> stdout error at interpreter shutdown fails to return OS error status
messages: + msg113330
versions: - Python 2.7
2010-08-04 23:35:06pitrousetfiles: + devfull.patch
versions: + Python 3.1, Python 3.2
nosy: + pitrou

messages: + msg112923

keywords: + patch
2010-08-04 23:04:13terry.reedysetnosy: + terry.reedy

messages: + msg112919
versions: + Python 2.7, - Python 2.5
2010-08-01 15:07:10georg.brandllinkissue5320 superseder
2010-08-01 15:06:53georg.brandlsetnosy: + georg.brandl
messages: + msg112342
2009-02-19 17:43:11mkcsetmessages: + msg82484
components: + Interpreter Core
2009-02-19 17:38:00mkccreate