import functools import _testcapi import sys final_func = _testcapi.get_recursion_depth def pyfunc(depth): if depth > 2: return partial_func(depth - 2) else: return final_func() partial_func = functools.partial(pyfunc) depth = 100 sys.setrecursionlimit(depth * 3) rec = pyfunc(depth) print("got: %s, expected: %s" % (rec, depth))