8000 gh-136186: Fix race condition in test_external_inspection.test_only_active_thread by pablogsal · Pull Request #136347 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-136186: Fix race condition in test_external_inspection.test_only_active_thread #136347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Lib/test/test_external_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
"""
Expand Down Expand Up @@ -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)
Expand Down
Loading
0