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.

classification
Title: sys.setrecursionlimit(2**30) breaks interactive shell
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, python-dev
Priority: normal Keywords: 3.3regression

Created on 2013-09-27 01:44 by Arfrever, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg198460 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2013-09-27 01:44
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(2**31), as expected, raises OverflowError.
Values like 2**31-1 (i.e. 2147483647) cause no problem:

$ python3.4 -q
>>> import sys
>>> sys.setrecursionlimit(2**31)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: signed integer is greater than maximum
>>> sys.setrecursionlimit(2**31-1)
>>> sys.getrecursionlimit()
2147483647
>>> 0
0
>>> 

Lower limit of values of recursion limit, which cause this bug: 715827883 == 2**29 + 2**27 + 2**25 + 2**23 + 2**21 + 2**19 + 2**17 + 2**15 + 2**13 + 2**11 + 2**9 + 2**7 + 2**5 + 2**3 + 2**1 + 1
Upper limit of values of recursion limit, which cause this bug: 1431655765 == 2**30 + 2**28 + 2**26 + 2**24 + 2**22 + 2**20 + 2**18 + 2**16 + 2**14 + 2**12 + 2**10 + 2**8 + 2**6 + 2**4 + 2**2 + 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.
msg198461 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-09-27 02:22
New changeset c3df31cbcd0a by Benjamin Peterson in branch '3.3':
don't scale compiler stack frames if the recursion limit is huge (closes #19098)
http://hg.python.org/cpython/rev/c3df31cbcd0a

New changeset 9a7ec433bf59 by Benjamin Peterson in branch 'default':
merge 3.3 (#19098)
http://hg.python.org/cpython/rev/9a7ec433bf59
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63297
2013-09-27 02:22:13python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg198461

resolution: fixed
stage: resolved
2013-09-27 01:44:24Arfrevercreate