0

I am trying to get the current recursion depth of a python script at a particular time in the script. The function getrecursiondepth() was suggested to me but I keep getting the error that such function does not exist in the sys.pyi module.

Does this function really not exist at all in any existing python module and if not is there any other way I can go about getting the recursion depth I need?

Note: I am not looking to get the recursion limit, just the recursion depth.

Here is the code that was suggested to me:

def recursion_depth():
depth = sys.getrecursiondepth()
with open("recursion_depth.txt", "a") as f:
    f.write(f"Recursion depth: {depth}\n")
if depth < sys.getrecursionlimit():
    recursion_depth()

recursion_depth()

  • Why do you think it should? https://docs.python.org/3/library/sys.html only documents `getrecursionlimit` – tripleee Apr 04 '23 at 09:11
  • As an aside, your indentation is clearly wrong, which is a problem in a language where whitespace is significant. On the desktop version of this site, you can get code marked up for you by pasting your code, selecting the pasted block, and typing ctrl-K. – tripleee Apr 04 '23 at 09:12

0 Answers0