Skip to content

Commit aaa31b9

Browse files
asvetlovclaude
andcommitted
gh-160986: Fix flaky test_popping_python_frame_is_not_native
The unwinder can attach before the target process enters its main loop, so on slow builds (e.g. UBSan) all 10,000 samples could be taken before leaf() runs. Wait until leaf() shows up in a sample before counting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9c0cfb1 commit aaa31b9

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎Lib/test/test_external_inspection.py‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,17 +2041,29 @@ def leaf(depth):
20412041
except RuntimeError:
20422042
continue
20432043
break
2044-
samples = 0
2045-
for _ in range(10_000):
2044+
2045+
def sample_names():
20462046
try:
20472047
threads = unwinder.get_stack_trace()[0].threads
20482048
except TRANSIENT_ERRORS:
2049-
continue
2049+
return None
20502050
if not threads:
2051-
continue
2052-
frames = threads[0].frame_info
2053-
names = [frame.funcname for frame in frames]
2051+
return None
2052+
names = [frame.funcname for frame in threads[0].frame_info]
20542053
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:
20552067
continue
20562068
samples += 1
20572069
self.assertNotIn(("leaf", "<native>"), zip(names, names[1:]))

0 commit comments

Comments
 (0)