maximum recursion depth

Tim Peters tim.one at comcast.net
Sun Jul 21 16:26:46 EDT 2002


[Paul, recursing very deeply]
> unfortunately it is not just memory...
> it will (did) crash when the stack size is full, which is only a
> fraction of the total memory space... right?

The size of the stack you get depends on your operating system, and perhaps
also your platform C runtime implementation -- it's not Python's decision.
If you tell us which OS you're using, someone may be able to tell you how to
tell your OS that you want a larger stack.  If you're using threads too,
life can get more complicated in a hurry, because most OS thread
implementations give threads relatively tiny stacks by default.

> python used less than 6MByte (less than 1% of total) when it
> crashed with a much higher limit set for the recursion depth.
> It took an awful lot of processing time as well... Have to rethink my
> strategy here.

Function calls in Python aren't cheap either.  Keeping a stack or queue of
"work to do" in an iterative algorithm ("a loop") is often much faster.






More information about the Python-list mailing list