[Python-Dev] Limiting the recursion limit

Guido van Rossum guido at python.org
Wed Jan 11 18:34:28 CET 2006


On 1/11/06, skip at pobox.com <skip at pobox.com> wrote:
>
>     >>> sys.setrecursionlimit(1<<30)
>     >>> f = lambda f:f(f)
>     >>> f(f)
>     Segmentation fault
>
> Is there some way that Python can determine that 1<<30 is an unreasonable
> recursion limit?

Yes, but that doesn't help -- there's some value in the middle where
you may or may not get a crash depending on random other stuff that is
going on, and the only way to know is to try. It's easy enough to code
a loop that tries higher and higher values until it finds a crash.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list