You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gh-138709: Fix race condition in test_external_inspection (#139209)
Fix race condition in test_external_inspection thread status tests
The tests test_thread_status_detection and test_thread_status_gil_detection
had a race condition where the test could sample thread status between when
the sleeper thread sends its "ready" message and when it actually calls
time.sleep(). This caused intermittent test failures where the sleeper
thread would show as running (status=0) instead of idle (status=1 or 2).
The fix moves the thread status collection inside the retry loop and
specifically waits for the expected thread states before proceeding with
assertions. The retry loop now continues until:
- The sleeper thread shows as idle (status=1 for CPU mode, status=2 for GIL mode)
- The busy thread shows as running (status=0)
- Both thread IDs are found in the status collection
This ensures the test waits for threads to settle into their expected states
before making assertions, eliminating the race condition.
0 commit comments