Skip to content

Commit 30c5af2

Browse files
committed
psfgh-174: Support free-threading CPython by disabling psutil related features
1 parent c960443 commit 30c5af2

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

doc/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
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+
Patch by Donghee Na.
9+
* Fix mem_max_rss measurement on macOS.
10+
Patch by Mike Droettboom.
11+
412
Version 2.6.2 (2023-11-02)
513
---------------------------
614

pyperf/_collect_metadata.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
resource = None
1212

1313
try:
14+
from pyperf._utils import IS_FREE_THREADING
1415
# Optional dependency
15-
import psutil
16+
if IS_FREE_THREADING:
17+
psutil = None
18+
else:
19+
import psutil
1620
except ImportError:
1721
psutil = None
1822

pyperf/_cpu_utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
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, IS_FREE_THREADING
66

77
try:
88
# Optional dependency
9-
import psutil
9+
if IS_FREE_THREADING:
10+
psutil = None
11+
else:
12+
import psutil
1013
except ImportError:
1114
psutil = None
1215

@@ -152,7 +155,10 @@ def set_cpu_affinity(cpus):
152155
return True
153156

154157
try:
155-
import psutil
158+
if IS_FREE_THREADING:
159+
return
160+
else:
161+
import psutil
156162
except ImportError:
157163
return
158164

@@ -166,7 +172,10 @@ def set_cpu_affinity(cpus):
166172

167173
def set_highest_priority():
168174
try:
169-
import psutil
175+
if IS_FREE_THREADING:
176+
return
177+
else:
178+
import psutil
170179
except ImportError:
171180
return
172181

pyperf/_psutil_memory.py

Lines changed: 5 additions & 1 deletion
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 IS_FREE_THREADING
4+
if IS_FREE_THREADING:
5+
raise ImportError
6+
else:
7+
import psutil
48
except ImportError:
59
raise ImportError('psutil is not installed')
610
import threading

pyperf/_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
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+
IS_FREE_THREADING = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
1011
MS_WINDOWS = (sys.platform == 'win32')
1112
MAC_OS = (sys.platform == 'darwin')
1213

0 commit comments

Comments
 (0)