Jan Langer schrieb:
Gabriel Genellina schrieb:
En Tue, 15 Dec 2009 11:17:20 -0300, Jan Langer <jan.lan...@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.


thanks for the quick answer. PyErr_WriteUnraisable calls PyErr_Fetch first, which should clear the error indicator, and the PyErr_Occurred in PyFile_WriteString should return false.

When thinking about it, it might be possible that the writing to the StringIO object will hit the recursion limit, too. But then I would expect a inifinte loops of

1 write to stderr
2 raise recursion exception
3 detect the error
4 call writeunraisable
5 write to stderr
6 loop to 2

But I have no overview happens exactly. :-)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to