Skip to content

Commit e684ada

Browse files
committed
Refactor RemoteUnwinder to use kwargs for thread parameters per review
1 parent e87439e commit e684ada

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

Lib/profiling/sampling/sample.py

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

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"))
44+
_FREE_THREADED_BUILD = sysconfig.get_config_var("Py_GIL_DISABLED") is not None
4645

4746
# Minimum number of samples required before showing the TUI
4847
# If fewer samples are collected, we skip the TUI and just print a message
@@ -66,27 +65,23 @@ def __init__(self, pid, sample_interval_usec, all_threads, *, mode=PROFILING_MOD
6665
self.realtime_stats = False
6766

6867
def _new_unwinder(self, native, gc, opcodes, skip_non_matching_threads):
69-
if _FREE_THREADED_BUILD:
70-
unwinder = _remote_debugging.RemoteUnwinder(
71-
self.pid, all_threads=self.all_threads, mode=self.mode, native=native, gc=gc,
72-
opcodes=opcodes, skip_non_matching_threads=skip_non_matching_threads,
73-
cache_frames=True, stats=self.collect_stats
74-
)
68+
kwargs = {}
69+
if _FREE_THREADED_BUILD or self.all_threads:
70+
kwargs['all_threads'] = self.all_threads
7571
else:
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-
)
89-
return unwinder
72+
kwargs['only_active_thread'] = bool(self.all_threads)
73+
74+
return _remote_debugging.RemoteUnwinder(
75+
self.pid,
76+
mode=self.mode,
77+
native=native,
78+
gc=gc,
79+
opcodes=opcodes,
80+
skip_non_matching_threads=skip_non_matching_threads,
81+
cache_frames=True,
82+
stats=self.collect_stats,
83+
**kwargs
84+
)
9085

9186
def sample(self, collector, duration_sec=None, *, async_aware=False):
9287
sample_interval_sec = self.sample_interval_usec / 1_000_000

0 commit comments

Comments
 (0)