Can python throw a “stack overflow” error?
You can, if your recursion limit is too high:
def foo():
return foo()
>>> foo()
Result:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
.......
File "<stdin>", line 2, in foo
RuntimeError: maximum recursion depth exceeded
>>>
The default recursion limit is 10**3
(verifiable via sys.getrecursionlimit
), but you can change it using sys.setrecursionlimit
:
import sys
sys.setrecursionlimit(10**8)
def foo():
foo()
but doing so could be dangerous: the standard limit is a little conservative, but Python stackframes can be quite big.
Read more here: Source link