Increase Python Stack Size

155 views Asked by At

Right off the bat: Yes I've tried threading.stack_size(biggest_number_windows10_allows) with Thread(target=some_function, args=(arg1, arg2)).

I also increased the maximum recursion depth to 4 million + (this depth is much larger than my code will ever need).

Print statements show the recursive function executing, but then it silently fails when the stack size limit is reached.

Question

What are other ways I can get around the stack size limit, or issue, here? Can making a compiled extension with Cython circumvent this issue somehow?

To answer some others, I'm 98% confident this issue cannot be solved without recursion. I've thought about it quite a bit, and I'm not sure how. Even my thought trains that make this horrendously complex don't seem to work out.

Need recursion on this one :)

1

There are 1 answers

0
scotty-nukem On

I ultimately figured out my own question.

Solution:

I used numba to implement the recursive function. This allowed me to both use the size of C types (true int size vs. Python's 24 byte behemoths).

In addition, I specified 16 bit ints, which further reduced the stack size of each call.

Nice bonus, each recursive function takes to the order of hundreds of milliseconds. Much faster than the python version. This code was not performance critical though.