https://github.com/python/cpython/commit/78c12273810036f555c515e807887b9d1473f12b
commit: 78c12273810036f555c515e807887b9d1473f12b
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: pablogsal <pablog...@gmail.com>
date: 2025-07-08T12:48:03Z
summary:

[3.14] gh-136186: Fix race condition in 
test_external_inspection.test_only_active_thread (GH-136347) (#136416)

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 0f31c225e68de3..44890ebfe5f76d 100644
--- a/Lib/test/test_external_inspection.py
+++ b/Lib/test/test_external_inspection.py
@@ -5,6 +5,7 @@
 import sys
 import socket
 import threading
+import time
 from asyncio import staggered, taskgroups, base_events, tasks
 from unittest.mock import ANY
 from test.support import os_helper, SHORT_TIMEOUT, busy_retry, 
requires_gil_enabled
@@ -930,9 +931,6 @@ def main_work():
             # Signal threads to start waiting
             ready_event.set()
 
-            # Give threads time to start sleeping
-            time.sleep(0.1)
-
             # Now do busy work to hold the GIL
             main_work()
             """
@@ -967,7 +965,23 @@ def main_work():
 
                 # Get stack trace with all threads
                 unwinder_all = RemoteUnwinder(p.pid, all_threads=True)
-                all_traces = unwinder_all.get_stack_trace()
+                for _ in range(10):
+                    # Wait for the main thread to start its busy work
+                    all_traces = unwinder_all.get_stack_trace()
+                    found = False
+                    for thread_id, stack in all_traces:
+                        if not stack:
+                            continue
+                        current_frame = stack[0]
+                        if current_frame.funcname == "main_work" and 
current_frame.lineno >15:
+                            found = True
+
+                    if found:
+                        break
+                    # Give a bit of time to take the next sample
+                    time.sleep(0.1)
+                else:
+                    self.fail("Main thread did not start its busy work on 
time")
 
                 # Get stack trace with only GIL holder
                 unwinder_gil = RemoteUnwinder(p.pid, only_active_thread=True)

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to