sys.stderr and PyErr_WriteUnraisable
Jan Langer
jan.langer at etit.tu-chemnitz.de
Tue Dec 15 11:20:35 EST 2009
Gabriel Genellina schrieb:
> 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.
>
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.
More information about the Python-list
mailing list