超过python最大递归深度

超过python最大递归深度,python,recursion,Python,Recursion,我想为任何java项目制作一个返回caller和callee的程序。 我有这个方法: def searchformethod(methodcalls,method): for call in methodcalls: if method in call[4]: calll=call[0],call[2] callerncallee.methodcaller.append(calll) callerncall

我想为任何java项目制作一个返回caller和callee的程序。
我有这个方法:

def searchformethod(methodcalls,method):
    for call in methodcalls:
        if method in call[4]:
           calll=call[0],call[2]
           callerncallee.methodcaller.append(calll)
           callerncallee.searchformethod(methodcalls,call[2])
methodcalls中的每个调用都包含(“类”、“调用方”、“被调用方”)
我需要一个递归来获得每一个方法,它在小项目中运行良好,
但是在大项目中我得到了这个

 callerncallee.searchformethod(methodcalls,call[2])
 [Previous line repeated 989 more times]
 RecursionError: maximum recursion depth exceeded

Python没有对尾部递归进行优化,这意味着对于每个递归步骤,堆栈都会增加,直到达到极限。然后你会得到错误信息,就像你得到的一样

您必须将递归调用转换为while循环