Issue 19098: sys.setrecursionlimit(2**30) breaks interactive shell (original) (raw)
sys.setrecursionlimit(2**30) breaks interactive shell in Python >=3.3. This bug does not occur during non-interactive execution of scripts / modules. This bug does not occur in versions of Python older than 3.3.
This bug occurs only for some range of values of recursion limit. There are higher values, which do not cause this bug. sys.setrecursionlimit(231), as expected, raises OverflowError. Values like 231-1 (i.e. 2147483647) cause no problem:
$ python3.4 -q
import sys sys.setrecursionlimit(231) Traceback (most recent call last): File "", line 1, in OverflowError: signed integer is greater than maximum sys.setrecursionlimit(231-1) sys.getrecursionlimit() 2147483647 0 0
Lower limit of values of recursion limit, which cause this bug: 715827883 == 229 + 227 + 225 + 223 + 221 + 219 + 217 + 215 + 213 + 211 + 29 + 27 + 25 + 23 + 21 + 1 Upper limit of values of recursion limit, which cause this bug: 1431655765 == 230 + 228 + 226 + 224 + 222 + 220 + 218 + 216 + 214 + 212 + 210 + 28 + 26 + 24 + 22 + 1
Example of this bug:
$ python3.4 -q
import sys sys.setrecursionlimit(2**30) 0 RuntimeError: maximum recursion depth exceeded during compilation "a" RuntimeError: maximum recursion depth exceeded during compilation
RuntimeError: maximum recursion depth exceeded during compilation
RuntimeError occurs for each line (even empty). Ctrl+D still works.
I use 64-bit GNU/Linux.