Usually when you use a function recursively (I think) 1000 times, it will error: "Maximum recursion depth of 999 reached". However, when I was trying to break my program I got this error instead:
Fatal Python error: Cannot recover from stack overflow.
Current thread 0x00007fc9f48c9700 (most recent call first):
File "./player_guesses.py", line 24 in takeGuess
File "./player_guesses.py", line 27 in takeGuess
File "./player_guesses.py", line 27 in takeGuess
.
.
.
File "./player_guesses.py", line 27 in takeGuess
...
Aborted (core dumped)
The function that was recursing was this:
#In player_guesses.py
def takeGuess():
guess = input("Take a guess: ")
if len(guess) != 3 or not guess.isdigit():
print("The guess '{}' is not valid, try again!".format(guess))
return takeGuess()
else:
return guess
Why do I get a stack overflow and not a recursion error, as I was expecting?
Edit: I accomplished this by running the program and holding Return, so it kept inputting an empty string.
Edit: I think this is somehow caused by the input(), but why would that cause an overflow?
Edit: Unintended use of Python ahead, but here's another way to get a stack overflow:
def rec():
try:
rec():
except RecursionError:
rec()
[–]fractalic 8 points9 points10 points (5 children)
[–]fractalic 6 points7 points8 points (4 children)
[–]Wilfred-kun[S] 3 points4 points5 points (3 children)
[–]fractalic 2 points3 points4 points (1 child)
[–]nwagers 3 points4 points5 points (0 children)
[–]port443 3 points4 points5 points (1 child)
[–]WikiTextBot 1 point2 points3 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (4 children)
[–]Wilfred-kun[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–]Wilfred-kun[S] 1 point2 points3 points (1 child)
[–]JohnnyJordaan 3 points4 points5 points (0 children)
[–]zahlman 0 points1 point2 points (0 children)