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: Recursion causes Crash
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, jack__d, michaeljwang10
Priority: normal Keywords:

Created on 2021-07-31 02:20 by michaeljwang10, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py michaeljwang10, 2021-07-31 02:20 Use the following code to replicate the bug
Messages (4)
msg398619 - (view) Author: Michael Wang (michaeljwang10) Date: 2021-07-31 02:20
Ultimately it seems that deep recursion after setting the recursion limit actually crashes python
msg398622 - (view) Author: Jack DeVries (jack__d) * Date: 2021-07-31 02:42
The default recursion limit is 1,000; you're increasing it by a factor of 10. It is documented that raising the recursion limit can cause crashes. What kind of crash are you seeing? Segmentation fault or stack overflow? Also, provide more details about your system: what OS and more importantly in this case, how much RAM?

It's possible that this is not a bug.
msg398623 - (view) Author: Jack DeVries (jack__d) * Date: 2021-07-31 02:44
Also, see related: bpo-44393
msg398627 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-07-31 03:45
Indeed, this behavior is documented at https://docs.python.org/3/library/sys.html?highlight=setrecursionlimit#sys.setrecursionlimit : "a too-high limit can lead to a crash".

I'd recommend refactoring to use iteration rather than recursion:

    def fact(n):
        product = 1
        for i in range(1, n+1):
            product *= i
        return product
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 88953
2021-07-31 03:45:52Dennis Sweeneysetstatus: open -> closed

nosy: + Dennis Sweeney
messages: + msg398627

resolution: not a bug
stage: resolved
2021-07-31 02:44:11jack__dsetmessages: + msg398623
2021-07-31 02:42:57jack__dsetnosy: + jack__d
messages: + msg398622
2021-07-31 02:20:58michaeljwang10create