0

Я не понимаю, почему случается Runtime Error. Код элементарный:

import sys
sys.setrecursionlimit(100000000)

def Rec(n):
    if n > 0:
        Rec(n - 1)

Rec(10000)

PyCharm выдает такое сообщение:

Process finished with exit code -1073741571 (0xC00000FD)

Глубина рекурсии всего лишь 10000, в чем же дело?

3
  • А в какой версии python выполняете? В версии 2.7.10 - выполняется. В версии 3.4.3 - нет.
    – 1d0
    29 дек 2015 в 14:24
  • Последняя версия Python - 3.5.1
    – pretttyman
    30 дек 2015 в 16:00
  • Попробуйте на 2.7.
    – 1d0
    12 янв 2016 в 7:33

1 ответ 1

1

Выдержка из документации

sys.setrecursionlimit(limit) Set the maximum depth of the Python interpreter stack to limit. 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 program that requires deep recursion and a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash.

Соответственно в зависимости от платформы существует максимальное значение, которое можно передать в функцию. Полагаю у вас оно меньше ста миллионов. Будьте скромнее

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.