(n)
| 25 | |
| 26 | @contextmanager |
| 27 | def 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 |
no outgoing calls
searching dependent graphs…