#That's a band-aid though. Instead of going into these crazy-deep (at least for Python, it would be another story in LISP or Haskell) recursions, you should rewrite your algorithm to an iterative one. If it is tail-recursive, a loop will suffice. In other cases, you can simply keep a list of tasks. For example, instead of

def fib(x):
   if x < 2: return x
   return fib(x-1) + fib(x-2)

#write

import collections
def fib_iter(x):
    tasks = collections.deque([x])
    res = 0
    while tasks:
        v = tasks.pop()
        if v < 2:
            res += v
            continue
        tasks.append(v-1)
        tasks.append(v-2)
    return res

for i in range(10):
    assert fib_iter(i) == fib(i), 'Got %r, expected %r for fib(%d)' % (fib_iter(i), fib(i), i)