Hi everyone,

It's time for yet another PEP :)

Fortunately, this one is a small one that doesn't change much.
It's aim is to make the VM more robust.

Abstract
========

This PEP proposes that machine stack overflow is treated differently from runaway recursion. This would allow programs to set the maximum recursion depth to fit their needs and provide additional safety guarantees.

The following program will run safely to completion:

    sys.setrecursionlimit(1_000_000)

    def f(n):
        if n:
            f(n-1)

    f(500_000)

The following program will raise a StackOverflow, without causing a VM crash:

    sys.setrecursionlimit(1_000_000)

    class X:
        def __add__(self, other):
            return self + other

    X() + 1

-----------

The full PEP can be found here:
https://www.python.org/dev/peps/pep-0651

As always, comments are welcome.

Cheers,
Mark.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ZY32N43YZJM3WYXSVD7OCGVNDGPR6DUM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to