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: Python 2.7.1 SegmentationFaults when given high recursion limit
Type: crash Stage:
Components: None Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, tdignan
Priority: normal Keywords:

Created on 2011-11-24 03:49 by tdignan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg148226 - (view) Author: Tom Dignan (tdignan) Date: 2011-11-24 03:49
On my system, the magic number to make this segfault seems to be 26200:

tom@tralfamadore ~/Downloads $ python recur1.py  26199
160164968

tom@tralfamadore ~/Downloads $ python recur1.py  26200
Segmentation fault

Here's the source:

#!/usr/bin/python
import sys

if len(sys.argv) < 2:
    print "usage %r <number>" % sys.argv[0]
    sys.exit(1)

number = int(sys.argv[1])

sys.setrecursionlimit(number + 2)

f = (lambda n: (f(n - 1) if n > 0 else 0) + 
    (n if n % 3 == 0 or n % 5 == 0 else 0))

print f(number)

sys.exit(0)
msg148229 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-11-24 05:22
Of course; that's what the recursion limit protects against.
History
Date User Action Args
2022-04-11 14:57:24adminsetgithub: 57677
2011-11-24 05:22:45benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg148229

resolution: not a bug
2011-11-24 03:49:54tdignancreate