Skip to content

Commit acace5b

Browse files
committed
Fix free threading
1 parent b75aee1 commit acace5b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Lib/profile/sample.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,30 @@
33
import pstats
44
import statistics
55
import time
6+
import sys
7+
import sysconfig
68
from collections import deque
79
from _colorize import ANSIColors
810

911
from .pstats_collector import PstatsCollector
1012
from .stack_collectors import CollapsedStackCollector
1113

14+
FREE_THREADED_BUILD = sysconfig.get_config_var("Py_GIL_DISABLED") is not None
1215

1316
class SampleProfiler:
1417
def __init__(self, pid, sample_interval_usec, all_threads):
1518
self.pid = pid
1619
self.sample_interval_usec = sample_interval_usec
1720
self.all_threads = all_threads
18-
only_active_threads = bool(self.all_threads)
19-
self.unwinder = _remote_debugging.RemoteUnwinder(
20-
self.pid, only_active_thread=only_active_threads
21-
)
21+
if FREE_THREADED_BUILD:
22+
self.unwinder = _remote_debugging.RemoteUnwinder(
23+
self.pid, all_threads=self.all_threads
24+
)
25+
else:
26+
only_active_threads = bool(self.all_threads)
27+
self.unwinder = _remote_debugging.RemoteUnwinder(
28+
self.pid, only_active_thread=only_active_threads
29+
)
2230
# Track sample intervals and total sample count
2331
self.sample_intervals = deque(maxlen=100)
2432
self.total_samples = 0

0 commit comments

Comments
 (0)