Author xdegaye
Recipients emptysquare, pitrou, serhiy.storchaka, vstinner, xdegaye
Date 2014-11-26.13:57:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> Why recursion limit is restored? Couldn't the test be simpler without it?

For the sake of explicitness, so that the interpreter will not raise a RuntimeError during finalization when checking for the recursion limit after g.throw(MyException) has raised PyExc_RecursionErrorInst.

> %a should be used instead of '%s' (file path can contain backslashes).
> And it would be more robust to open file in binary mode (may be even in non-buffered). It can contain non-ascii characters.
> May be the test should be marked as CPython only.
> To check that script is executed at all we should print something from it and than test the out. Otherwise syntax error in script will make all test passed.

New patch attached.

The reason why the PyExc_RecursionErrorInst singleton keeps the frames alive longer than expected is that the reference count of the PyExc_RecursionErrorInst static variable never reaches zero until _PyExc_Fini().  So decrementing the reference count of this exception after the traceback has been printed in PyErr_PrintEx() does not decrement the reference count of its traceback attribute (as it is the case with the other exceptions) and the traceback is not freed. The following patch to PyErr_PrintEx() does that.  With this new patch and without the changes made by warn_4.patch, the interpreter does not crash with the reproducer and the ResourceWarning is now printed instead of being ignored as with the warn_4.patch:

diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1876,6 +1876,8 @@
         PyErr_Display(exception, v, tb);
+    if (v == PyExc_RecursionErrorInst)
+        Py_CLEAR(((PyBaseExceptionObject *)v)->traceback);

If both patches were to be included, the test case in warn_4.patch would test the above patch and not the changes made in Python/_warnings.c.
Date User Action Args
2014-11-26 13:57:53xdegayesetrecipients: + xdegaye, pitrou, vstinner, serhiy.storchaka, emptysquare
2014-11-26 13:57:53xdegayesetmessageid: <>
2014-11-26 13:57:53xdegayelinkissue22898 messages
2014-11-26 13:57:53xdegayecreate