Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-26806: transparently add 25 to the recursion limit in IDLE
This is done to compensate for the extra stack frames added by
IDLE itself, which cause problems when setting the recursion limit
to low values.

This wraps sys.setrecursionlimit() and sys.getrecursionlimit()
as invisibly as possible.
  • Loading branch information
taleinat committed Jun 10, 2019
commit 062b111a695cd9f7e30f92b5d4862e4383031d43
39 changes: 39 additions & 0 deletions Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import linecache
import queue
import sys
import textwrap
import time
import traceback
import _thread as thread
Expand Down Expand Up @@ -474,6 +475,44 @@ def __init__(self, rpchandler):
self.calltip = calltip.Calltip()
self.autocomplete = autocomplete.AutoComplete()

self._wrap_sys_setrecursionlimit()

def _wrap_sys_setrecursionlimit(self):
code = textwrap.dedent("""\
import sys
from functools import wraps

# add the delta to the default recursion limit, to compensate
sys.setrecursionlimit(sys.getrecursionlimit() + 25)

@wraps(sys.setrecursionlimit)
def setrecursionlimit(*args, **kwargs):
# mimic the original sys.setrecursionlimit()'s input handling
if kwargs:
raise TypeError(
"setrecursionlimit() takes no keyword arguments")
try:
limit, = args
except ValueError:
raise TypeError("setrecursionlimit() takes exactly one "
"argument ({} given)".format(len(args)))
if not limit > 0:
raise ValueError(
"recursion limit must be greater or equal than 1")

return setrecursionlimit.__wrapped__(limit + 25)
sys.setrecursionlimit = setrecursionlimit

@wraps(sys.getrecursionlimit)
def getrecursionlimit():
return getrecursionlimit.__wrapped__() - 25
sys.getrecursionlimit = getrecursionlimit

del sys
del wraps
""")
exec(code, self.locals)
Comment thread
terryjreedy marked this conversation as resolved.
Outdated

def runcode(self, code):
global interruptable
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Transparently add 25 to the recursion limit in IDLE's shell to compensate
for stack frames added by IDLE. Patch by Tal Einat.