MCPcopy Index your code
hub / github.com/python/cpython / get_recursion_depth

Function get_recursion_depth

Lib/test/support/__init__.py:2472–2493  ·  view source on GitHub ↗

Get the recursion depth of the caller function. In the __main__ module, at the module level, it should be 1.

()

Source from the content-addressed store, hash-verified

2470 testcase.assertRaisesRegex(TypeError, msg, tp.__new__, tp, *args, **kwds)
2471
2472def get_recursion_depth():
2473 """Get the recursion depth of the caller function.
2474
2475 In the __main__ module, at the module level, it should be 1.
2476 """
2477 try:
2478 import _testinternalcapi
2479 depth = _testinternalcapi.get_recursion_depth()
2480 except (ImportError, RecursionError) as exc:
2481 # sys._getframe() + frame.f_back implementation.
2482 try:
2483 depth = 0
2484 frame = sys._getframe()
2485 while frame is not None:
2486 depth += 1
2487 frame = frame.f_back
2488 finally:
2489 # Break any reference cycles.
2490 frame = None
2491
2492 # Ignore get_recursion_depth() frame.
2493 return max(depth - 1, 1)
2494
2495def get_recursion_available():
2496 """Get the number of available frames before RecursionError.

Callers 2

get_recursion_availableFunction · 0.85
infinite_recursionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…