gh-143423: Fix free-threaded build detection in sampling profiler
Description
This PR corrects a logic error in Lib/profiling/sampling/sample.py where _FREE_THREADED_BUILD was incorrectly evaluated as True on Windows non-free-threaded builds when Py_GIL_DISABLED was explicitly set to 0.
The detection has been updated from an is not None check to a bool() cast, which correctly handles:
-
1->True -
0->False -
None->False(standard builds)
Additionally, I have updated _new_unwinder to properly handle the all_threads vs only_active_thread parameters based on the detected build type.
Tests
- Verified reproduction by checking that
_FREE_THREADED_BUILDreturnsFalsewhensysconfig.get_config_var("Py_GIL_DISABLED")is0. - Ran the official test suite:
./python -m test test_profiling(Passed).
- Issue: gh-143423
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.
If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.
@pablogsal up for review
cc @pablogsal