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 <1461183609.61.0.881469081182.issue26806@psf.upfronthosting.co.za>
In-reply-to
Content
Interesting idea.  We avoid the problem by adding something like the following to run.py

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

This works when entered interactively, and I presume it would within run.py.  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.
History
Date User Action Args
2016-04-20 20:20:09terry.reedysetrecipients: + terry.reedy, serhiy.storchaka
2016-04-20 20:20:09terry.reedysetmessageid: <1461183609.61.0.881469081182.issue26806@psf.upfronthosting.co.za>
2016-04-20 20:20:09terry.reedylinkissue26806 messages
2016-04-20 20:20:09terry.reedycreate