Core dump with increased recursionlimit

Nick Craig-Wood nick at craig-wood.com
Tue Oct 12 05:29:58 EDT 2004


I've just discovered that my python (Python 2.3.4 from debian package
2.3.4-1 running on debian testing x86 + linux 2.4.26) core dumps when
I set recursionlimit very high and do lots of recursion.

Eg

$ python -c 'import sys; sys.setrecursionlimit(100000)
def f(): return f()
f()'
Segmentation fault (core dumped)

The recursion limit at which it does a core dump rather than a
"RuntimeError: maximum recursion depth exceeded" is about 7235 on my
system.  (I binary searched it).  However this number isn't constant!

Other interesting info

$ ulimit -a
core file size        (blocks, -c) 1000000
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) unlimited
max memory size       (kbytes, -m) unlimited
open files                    (-n) 1024
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) unlimited
cpu time             (seconds, -t) unlimited
max user processes            (-u) 7168
virtual memory        (kbytes, -v) unlimited

So stack size should be unlimited.

The backtrace looks like this...

#0  0x400301ac in __pthread_alt_trylock () from /lib/libpthread.so.0
#1  0x40114003 in malloc () from /lib/libc.so.6
#2  0x080df577 in _PyObject_GC_Malloc ()
#3  0x080df67d in _PyObject_GC_NewVar ()
#4  0x080fb863 in PyFrame_New ()
#5  0x080ab8e1 in PyEval_CallObjectWithKeywords ()
#6  0x080ab6dc in PyEval_CallObjectWithKeywords ()
#7  0x080a9b9e in Py_MakePendingCalls ()
#8  0x080ab91d in PyEval_CallObjectWithKeywords ()
#9  0x080ab6dc in PyEval_CallObjectWithKeywords ()
#10 0x080a9b9e in Py_MakePendingCalls ()
#11 0x080ab91d in PyEval_CallObjectWithKeywords ()
#12 0x080ab6dc in PyEval_CallObjectWithKeywords ()
#13 0x080a9b9e in Py_MakePendingCalls ()

[snip many similar lines!]

#21713 0x080ab91d in PyEval_CallObjectWithKeywords ()
#21714 0x080ab6dc in PyEval_CallObjectWithKeywords ()
#21715 0x080a9b9e in Py_MakePendingCalls ()
#21716 0x080aa72c in PyEval_EvalCodeEx ()
#21717 0x080acf29 in PyEval_EvalCode ()
#21718 0x080d90ab in PyRun_FileExFlags ()
#21719 0x080d9c31 in PyRun_SimpleStringFlags ()
#21720 0x08054dc2 in Py_Main ()
#21721 0x080549eb in main ()

I don't have the debugging symbols for this version of python though
so can't provide more detail.

I'm pretty sure this isn't a limit of my linux setup.  I compiled and
ran this C program

#include <stdio.h>
#include <string.h>

#define MB 256
#define SIZE (MB*1024*1024)

int main(void)
{
    char blob[SIZE];
    memset(blob, 0x55, SIZE);
    printf("blob = %p, %d, %d\n", blob, blob[0], blob[SIZE-1]);
    return 0;
}

Which runs fine and shows I can have 256 MB of stack.  (Also the
python core dump is only 6 MB)

Any ideas?  Problem with my setup? Linux bug? Python bug? Problem
between chair and keyboard?

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list