![]() |
sys.stderr and PyErr_WriteUnraisable
Hi all,
I am using Python 2.6 and with the following code I expect a different result: 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. I looked a little into Python and the warnings are printed from PyErr_WriteUnraisable to sys.stderr. Is this code supposed to work as I expect it or am I missing something? thanks, Jan |
Re: sys.stderr and PyErr_WriteUnraisable
En Tue, 15 Dec 2009 11:17:20 -0300, Jan Langer
<jan.langer@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 |
Re: sys.stderr and PyErr_WriteUnraisable
Gabriel Genellina schrieb:
> En Tue, 15 Dec 2009 11:17:20 -0300, Jan Langer > <jan.langer@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. |
Re: sys.stderr and PyErr_WriteUnraisable
Jan Langer schrieb:
> Gabriel Genellina schrieb: >> En Tue, 15 Dec 2009 11:17:20 -0300, Jan Langer >> <jan.langer@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. :-) |
| All times are GMT. The time now is 02:05 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.