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. |