cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-143423: Fix free-threaded build detection in sampling profiler

Open DCchoudhury15 opened this issue 1 week ago • 2 comments

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_BUILD returns False when sysconfig.get_config_var("Py_GIL_DISABLED") is 0.
  • Ran the official test suite: ./python -m test test_profiling (Passed).
  • Issue: gh-143423

DCchoudhury15 avatar Jan 05 '26 04:01 DCchoudhury15

All commit authors signed the Contributor License Agreement.

CLA signed

python-cla-bot[bot] avatar Jan 05 '26 04:01 python-cla-bot[bot]

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.

bedevere-app[bot] avatar Jan 05 '26 04:01 bedevere-app[bot]

@pablogsal up for review

DCchoudhury15 avatar Jan 06 '26 08:01 DCchoudhury15

cc @pablogsal

vstinner avatar Jan 08 '26 16:01 vstinner