https://github.com/python/cpython/commit/eeafc73b70f9cff382390cf9d9548b80ea2cefd5
commit: eeafc73b70f9cff382390cf9d9548b80ea2cefd5
branch: main
author: Andrew Svetlov <[email protected]>
committer: asvetlov <[email protected]>
date: 2026-11-02T20:40:09+01:00
summary:

gh-160986: Fix flaky test_popping_python_frame_is_not_native (#161073)

* 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 <[email protected]>

* Reuse _get_stack_trace_with_retry() to wait for leaf()

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

files:
M Lib/test/test_external_inspection.py

diff --git a/Lib/test/test_external_inspection.py 
b/Lib/test/test_external_inspection.py
index df0af14d9f7562..a3f2eabacf6e88 100644
--- a/Lib/test/test_external_inspection.py
+++ b/Lib/test/test_external_inspection.py
@@ -2041,6 +2041,14 @@ def leaf(depth):
                 except RuntimeError:
                     continue
                 break
+            # The unwinder can attach before the main loop starts.
+            _get_stack_trace_with_retry(
+                unwinder,
+                condition=lambda trace: trace[0].threads and any(
+                    frame.funcname == "leaf"
+                    for frame in trace[0].threads[0].frame_info
+                ),
+            )
             samples = 0
             for _ in range(10_000):
                 try:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to