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.
P
Pablo Galindo Salgado committed
9df477c0ce7ac896d75d3bb06c3dd14808cd659a
Parent: 080faf2
Committed by GitHub <noreply@github.com>
on 9/21/2025, 5:32:03 PM