Skip to content

Commit 2e57778

Browse files
asvetlovclaude
andcommitted
Reuse _get_stack_trace_with_retry() to wait for leaf()
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent aaa31b9 commit 2e57778

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

‎Lib/test/test_external_inspection.py‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,29 +2041,25 @@ def leaf(depth):
20412041
except RuntimeError:
20422042
continue
20432043
break
2044-
2045-
def sample_names():
2044+
# The unwinder can attach before the main loop starts.
2045+
_get_stack_trace_with_retry(
2046+
unwinder,
2047+
condition=lambda trace: trace[0].threads and any(
2048+
frame.funcname == "leaf"
2049+
for frame in trace[0].threads[0].frame_info
2050+
),
2051+
)
2052+
samples = 0
2053+
for _ in range(10_000):
20462054
try:
20472055
threads = unwinder.get_stack_trace()[0].threads
20482056
except TRANSIENT_ERRORS:
2049-
return None
2057+
continue
20502058
if not threads:
2051-
return None
2052-
names = [frame.funcname for frame in threads[0].frame_info]
2059+
continue
2060+
frames = threads[0].frame_info
2061+
names = [frame.funcname for frame in frames]
20532062
if "leaf" not in names:
2054-
return None
2055-
return names
2056-
2057-
# Wait until the target is running leaf(): the unwinder can
2058-
# attach before the main loop starts on slow builds.
2059-
for _ in busy_retry(SHORT_TIMEOUT):
2060-
if sample_names() is not None:
2061-
break
2062-
2063-
samples = 0
2064-
for _ in range(10_000):
2065-
names = sample_names()
2066-
if names is None:
20672063
continue
20682064
samples += 1
20692065
self.assertNotIn(("leaf", "<native>"), zip(names, names[1:]))

0 commit comments

Comments
 (0)