MCPcopy
hub / github.com/msgspec/msgspec / max_call_depth

Function max_call_depth

tests/unit/utils.py:27–47  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

25
26@contextmanager
27def max_call_depth(n):
28 cur_depth = len(inspect.stack(0))
29 orig = sys.getrecursionlimit()
30 try:
31 # Our measure of the current stack depth can be off by a bit. Trying to
32 # set a recursionlimit < the current depth will raise a RecursionError.
33 # We just try again with a slightly higher limit, bailing after an
34 # unreasonable amount of adjustments.
35 for i in range(64):
36 try:
37 sys.setrecursionlimit(cur_depth + i + n)
38 break
39 except RecursionError:
40 pass
41 else:
42 raise ValueError(
43 "Failed to set low recursion limit, something is wrong here"
44 )
45 yield
46 finally:
47 sys.setrecursionlimit(orig)
48
49
50@contextmanager

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…