Skip to content

Commit

Permalink
Extend tests for stackoverflow profile
Browse files Browse the repository at this point in the history
  • Loading branch information
fjetter committed Mar 8, 2023
1 parent 7780ad7 commit 80bb9ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
9 changes: 5 additions & 4 deletions distributed/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,15 @@ def process(
# which can cause recursion errors later on since this can generate
# deeply nested dictionaries
depth = min(250, sys.getrecursionlimit() // 4)
if depth <= 0:
return None

if any(frame.f_code.co_filename.endswith(o) for o in omit):
return None

prev = frame.f_back
if prev is not None and (
stop is None or not prev.f_code.co_filename.endswith(stop)
if (
depth > 0
and prev is not None
and (stop is None or not prev.f_code.co_filename.endswith(stop))
):
new_state = process(prev, frame, state, stop=stop, depth=depth - 1)
if new_state is None:
Expand Down
36 changes: 16 additions & 20 deletions distributed/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,23 +356,19 @@ def test_call_stack_f_lineno(f_lasti: int, f_lineno: int) -> None:


def test_stack_overflow():
old = sys.getrecursionlimit()
sys.setrecursionlimit(200)
try:
state = create()
frame = None

def f(i):
if i == 0:
nonlocal frame
frame = sys._current_frames()[threading.get_ident()]
return
else:
return f(i - 1)

f(sys.getrecursionlimit() - 100)
process(frame, None, state)
merge(state, state, state)

finally:
sys.setrecursionlimit(old)
state = create()
frame = None

def f(i):
if i == 0:
nonlocal frame
frame = sys._current_frames()[threading.get_ident()]
return
else:
return f(i - 1)

f(sys.getrecursionlimit() - 200)
process(frame, None, state)
assert state["children"]
assert state["count"]
assert merge(state, state, state)

0 comments on commit 80bb9ff

Please sign in to comment.