[issue24864] errors writing to stdout are uncatchable and exit with status 0

Robert Collins report at bugs.python.org
Fri Aug 14 10:59:02 CEST 2015


New submission from Robert Collins:

I was trying to demonstrate how testing some code is hard, and I stumbled upon this.

The following code should be debuggable when run with a bad stdout - e.g.

python foo.py > /dev/full

---
import sys
import traceback

import pdb;pdb.Pdb(stdout=sys.stderr).set_trace()
try:
    print("What... is your quest?")
except:
    sys.stderr.write("Exception in program.\n")
    traceback.print_exc(file=sys.stderr)
---

Here is a transcript of a session with it:
---
$ python ./02.py > /dev/full 
> /home/robertc/work/Presentations/reveal.js/effectsnippets/02.py(5)<module>()
-> try:
(Pdb) n
> /home/robertc/work/Presentations/reveal.js/effectsnippets/02.py(6)<module>()
-> print("What... is your quest?")
(Pdb) n
--Return--
> /home/robertc/work/Presentations/reveal.js/effectsnippets/02.py(6)<module>()->None
-> print("What... is your quest?")
(Pdb) n
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
OSError: [Errno 28] No space left on device
$ echo $?
0
---

The same thing done on stderr exits with an exit code of 0 as well.

----------
messages: 248570
nosy: rbcollins
priority: normal
severity: normal
status: open
title: errors writing to stdout are uncatchable and exit with status 0
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24864>
_______________________________________


More information about the Python-bugs-list mailing list