This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients serhiy.storchaka, terry.reedy
Date 2016-04-20.20:20:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Interesting idea.  We avoid the problem by adding something like the following to

_setrecursionlimit = sys.setrecursionlimit
def setrecursionlimit(n):
    _setrecursionlimit(max(n, 50))
sys.setrecursionlimit = setrecursionlimit

This works when entered interactively, and I presume it would within  For _setrecursionlimit to be accessible from user code (to reverse the monkey patching), it would have to be attached to the function as an attribute.

setrecursionlimit.original = _setrecursionlimit

Though user-friendly for most users, this would make IDLE execute code differently from raw Python.  The builtin has a lower limit, based on the current stack depth, but it raises instead of setting a higher limit.  I presume we could use len(inspect.stack()) to get the current 'recursion depth', and add, say, 30 rather than 3. (The current error message could be more helpful.)

>>> sys.setrecursionlimit(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RecursionError: cannot set the recursion limit to 3 at the recursion depth 1: the limit is too low
>>> sys.setrecursionlimit(4)
>>> f()
>>> def f():
...   print('f')
...   f()
>>> f()

The call to f seems to be silently ignored.  This does not seem helpful.

Whatever we do, I would mention it in a revision of the proposed paragraph above.
Date User Action Args
2016-04-20 20:20:09terry.reedysetrecipients: + terry.reedy, serhiy.storchaka
2016-04-20 20:20:09terry.reedysetmessageid: <>
2016-04-20 20:20:09terry.reedylinkissue26806 messages
2016-04-20 20:20:09terry.reedycreate