I am running this code whithout success.
import sys
sys.setrecursionlimit(2147483647)
Gi = 0
def recur():
global Gi
Gi = Gi + 1
recur()
recur()
print(Gi)
input()
I know that changing the recursion limit is no good, however I never thought that that could lead to the crash of the Shell. Someone knows why?
The documentation for sys.setrecursionlimit
specifically says:
This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python.
The highest possible limit is platform-dependent. A user may need to set the limit higher when they have [...] a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash.
That seems pretty clear to me. If you set the value too high, you can crash Python. Note that the documentation specifically refers to crashing Python, meaning the Python interpreter, not simply crashing your program.
On a Linux system you may be able to use the ulimit -s
command to change the operating system stack (recursion) limit. ulimit -s unlimited
will lift operating system limits on stack size, but you can still induce a crash by recursing until you exceed available physical memory in your machine.