Skip to content

Commit 2065359

Browse files
authored
gh-174: Support free-threading CPython by disabling psutil related fe… (#175)
1 parent c960443 commit 2065359

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

doc/changelog.rst

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
Version 2.6.3 (2024-03-05)
5+
---------------------------
6+
7+
* Support Free-threading CPython (PEP-703) by disabling psutil related features.
8+
Relevant issue: https://github.com/python/cpython/issues/116024.
9+
Patch by Donghee Na.
10+
* Fix mem_max_rss measurement on macOS.
11+
Patch by Mike Droettboom.
12+
413
Version 2.6.2 (2023-11-02)
514
---------------------------
615

pyperf/_collect_metadata.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
resource = None
1212

1313
try:
14-
# Optional dependency
15-
import psutil
14+
from pyperf._utils import USE_PSUTIL
15+
if not USE_PSUTIL:
16+
psutil = None
17+
else:
18+
import psutil
1619
except ImportError:
1720
psutil = None
1821

pyperf/_cpu_utils.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import os
33
import re
44

5-
from pyperf._utils import sysfs_path, proc_path, read_first_line
5+
from pyperf._utils import sysfs_path, proc_path, read_first_line, USE_PSUTIL
66

77
try:
8-
# Optional dependency
9-
import psutil
8+
if not USE_PSUTIL:
9+
psutil = None
10+
else:
11+
import psutil
1012
except ImportError:
1113
psutil = None
1214

@@ -152,7 +154,10 @@ def set_cpu_affinity(cpus):
152154
return True
153155

154156
try:
155-
import psutil
157+
if not USE_PSUTIL:
158+
return
159+
else:
160+
import psutil
156161
except ImportError:
157162
return
158163

@@ -166,7 +171,10 @@ def set_cpu_affinity(cpus):
166171

167172
def set_highest_priority():
168173
try:
169-
import psutil
174+
if not USE_PSUTIL:
175+
return
176+
else:
177+
import psutil
170178
except ImportError:
171179
return
172180

pyperf/_psutil_memory.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import os
22
try:
3-
import psutil
3+
from pyperf._utils import USE_PSUTIL
4+
if not USE_PSUTIL:
5+
raise ImportError
6+
else:
7+
import psutil
48
except ImportError:
59
raise ImportError('psutil is not installed')
610
import threading

pyperf/_utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import os
44
import statistics
55
import sys
6+
import sysconfig
67
from shlex import quote as shell_quote # noqa
78
from shutil import which
89

9-
10+
# Currently there is a packaging issue for PEP-703,
11+
# Until then psutil is disabled as a workaround.
12+
# See: https://github.com/python/cpython/issues/116024
13+
USE_PSUTIL = not bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
1014
MS_WINDOWS = (sys.platform == 'win32')
1115
MAC_OS = (sys.platform == 'darwin')
1216

0 commit comments

Comments
 (0)