For this recursive code, why does Python 2.7 not give an error, but 3.5 does?

Earlier today I read about this strange case in Python, Javaand JS:

try:
    return True
finally:
    return False

What returns False.

So, I decided to play with him:

def caseThree():
    try:
        caseThree()
    except:
        print("Error")
        caseThree()
    finally:
        return False
print(caseThree())

In Python, 2.7this returns:

Error
False

However in Python 3.5:

Error
Fatal Python error: Cannot recover from stack overflow.

Current thread 0x000025ec (most recent call first):
  File "`<stdin>`", line 3 in caseThree

the last line is repeated until you get: ...

Can someone explain why the code 2.7does not overflow the stack, but 3.5does?

+4
source share
1 answer

, , , , Lib/test/test_sys.py test_recursionlimit_fatalerror.

, , , segfault (, . ); Python 28179.

, , .

+2

Source: https://habr.com/ru/post/1662061/


All Articles