sys.stderr and PyErr_WriteUnraisable
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Dec 15 10:44:39 EST 2009
En Tue, 15 Dec 2009 11:17:20 -0300, Jan Langer
<jan.langer at etit.tu-chemnitz.de> escribió:
> from test.test_support import captured_output
> with captured_output("stderr") as stderr:
> def g():
> try:
> g()
> except RuntimeError,e:
> pass
> g()
> print stderr.getvalue()
>
> I expect the ignored exceptions to be printed into the StringIO object
> stderr. With this code there are no warnings on the command line, but
> getvalue() returns nothing.
If sys.stderr is not a real file, no error gets printed.
PyErr_WriteUnraisable calls PyFile_WriteString, which checks for non-file
objects and only writes to them when no error is set.
Seems to be a safety measure.
--
Gabriel Genellina
More information about the Python-list
mailing list