Skip to content

Commit

Permalink
psfgh-174: Support free-threading CPython by disabling psutil related…
Browse files Browse the repository at this point in the history
… features
  • Loading branch information
corona10 committed Mar 5, 2024
1 parent c960443 commit 30c5af2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
8 changes: 8 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

Version 2.6.3 (2024-03-05)
---------------------------

* Support Free-threading CPython (PEP-703) by disabling psutil related features.
Patch by Donghee Na.
* Fix mem_max_rss measurement on macOS.
Patch by Mike Droettboom.

Version 2.6.2 (2023-11-02)
---------------------------

Expand Down
6 changes: 5 additions & 1 deletion pyperf/_collect_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
resource = None

try:
from pyperf._utils import IS_FREE_THREADING
# Optional dependency
import psutil
if IS_FREE_THREADING:
psutil = None
else:
import psutil
except ImportError:
psutil = None

Expand Down
17 changes: 13 additions & 4 deletions pyperf/_cpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import os
import re

from pyperf._utils import sysfs_path, proc_path, read_first_line
from pyperf._utils import sysfs_path, proc_path, read_first_line, IS_FREE_THREADING

try:
# Optional dependency
import psutil
if IS_FREE_THREADING:
psutil = None
else:
import psutil
except ImportError:
psutil = None

Expand Down Expand Up @@ -152,7 +155,10 @@ def set_cpu_affinity(cpus):
return True

try:
import psutil
if IS_FREE_THREADING:
return
else:
import psutil
except ImportError:
return

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

def set_highest_priority():
try:
import psutil
if IS_FREE_THREADING:
return
else:
import psutil
except ImportError:
return

Expand Down
6 changes: 5 additions & 1 deletion pyperf/_psutil_memory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
try:
import psutil
from pyperf._utils import IS_FREE_THREADING
if IS_FREE_THREADING:
raise ImportError
else:
import psutil
except ImportError:
raise ImportError('psutil is not installed')
import threading
Expand Down
3 changes: 2 additions & 1 deletion pyperf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import os
import statistics
import sys
import sysconfig
from shlex import quote as shell_quote # noqa
from shutil import which


IS_FREE_THREADING = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
MS_WINDOWS = (sys.platform == 'win32')
MAC_OS = (sys.platform == 'darwin')

Expand Down

0 comments on commit 30c5af2

Please sign in to comment.