Title: segfault with sys.setrecursionlimit
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, jack__d, ultrabear
Priority: normal Keywords:

Created on 2021-06-11 09:27 by ultrabear, last changed 2021-07-28 23:27 by jack__d. This issue is now closed.

File name Uploaded Description Edit
segpy.png ultrabear, 2021-06-11 09:27 demonstration of segfault from high recursion limit
Messages (3)
msg395626 - (view) Author: Alex Hall (ultrabear) Date: 2021-06-11 09:27
Found on:
Python 3.9.5
GCC 11.1 on Linux (x86_64)
Reproduced on:
Python 3.9.5
Clang 9.0.8 Linux (arm)

When setting the recursion limit to a high enough amount, trying to reach that recursion limit ends in a segmentation fault (stack overflow?)

import sys

def recurse(n: int) -> int:


msg395632 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-06-11 13:16
That's the documented behavior: "A user may need to set the limit higher when they have a program that requires deep recursion and a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash."

Also, please don't post images. Copy and paste the text instead. Images aren't friendly to visually impaired people, and they can't be copy and pasted.
msg398443 - (view) Author: Jack DeVries (jack__d) * Date: 2021-07-28 23:27
What about low recursion limits? This program causes a segfault for me::

    import sys

    print('goodbye, world')
Date User Action Args
2021-07-28 23:27:23jack__dsetnosy: + jack__d
messages: + msg398443
2021-06-11 13:16:35eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg395632

resolution: not a bug
stage: resolved
2021-06-11 09:27:01ultrabearcreate