Skip to content

Commit dd0ec01

Browse files
committed
gh-143423: Fix free-threaded build detection in sampling profiler
1 parent 6d05e55 commit dd0ec01

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Lib/profiling/sampling/sample.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def _pause_threads(unwinder, blocking):
4141
except ImportError:
4242
LiveStatsCollector = None
4343

44-
_FREE_THREADED_BUILD = sysconfig.get_config_var("Py_GIL_DISABLED") is not None
44+
# FIX: Use bool() to correctly detect 0 as False on Windows non-free-threaded builds
45+
_FREE_THREADED_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
46+
4547
# Minimum number of samples required before showing the TUI
4648
# If fewer samples are collected, we skip the TUI and just print a message
4749
MIN_SAMPLES_FOR_TUI = 200
@@ -71,11 +73,19 @@ def _new_unwinder(self, native, gc, opcodes, skip_non_matching_threads):
7173
cache_frames=True, stats=self.collect_stats
7274
)
7375
else:
74-
unwinder = _remote_debugging.RemoteUnwinder(
75-
self.pid, only_active_thread=bool(self.all_threads), mode=self.mode, native=native, gc=gc,
76-
opcodes=opcodes, skip_non_matching_threads=skip_non_matching_threads,
77-
cache_frames=True, stats=self.collect_stats
78-
)
76+
# FIX: Properly handle all_threads vs only_active_thread parameters
77+
if self.all_threads:
78+
unwinder = _remote_debugging.RemoteUnwinder(
79+
self.pid, all_threads=self.all_threads, mode=self.mode, native=native, gc=gc,
80+
opcodes=opcodes, skip_non_matching_threads=skip_non_matching_threads,
81+
cache_frames=True, stats=self.collect_stats
82+
)
83+
else:
84+
unwinder = _remote_debugging.RemoteUnwinder(
85+
self.pid, only_active_thread=bool(self.all_threads), mode=self.mode, native=native, gc=gc,
86+
opcodes=opcodes, skip_non_matching_threads=skip_non_matching_threads,
87+
cache_frames=True, stats=self.collect_stats
88+
)
7989
return unwinder
8090

8191
def sample(self, collector, duration_sec=None, *, async_aware=False):

0 commit comments

Comments
 (0)