I'm not advocating that this would ever be a good idea, but I've found that you can crash Python (2.7 and 3.2 checked) by running eval
on a large enough input string:
def kill_python(N):
S = '+'.join((str(n) for n in xrange(N)))
return eval(S)
On my computer S
can be generated just fine, but for values of approximately N>74900
, Python will fail with Segmentation fault (core dumped)
. Is there a limit to the length of string (or parse tree) that the interpreter can handle?
Note: I don't need to do this, to me this is a deeper question reflecting my ignorance of what goes on inside the box. I'd like to understand why Python fails here, and so catastrophically (why not throw an exception?)