Terry J. Reedy added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26806>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com