diff --git a/doc/changelog.rst b/doc/changelog.rst index 378de1d6..6b57351a 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,15 @@ Changelog ========= +Version 2.6.3 (2024-03-05) +--------------------------- + +* Support Free-threading CPython (PEP-703) by disabling psutil related features. + Relevant issue: https://github.com/python/cpython/issues/116024. + Patch by Donghee Na. +* Fix mem_max_rss measurement on macOS. + Patch by Mike Droettboom. + Version 2.6.2 (2023-11-02) --------------------------- diff --git a/pyperf/_collect_metadata.py b/pyperf/_collect_metadata.py index e504ab6d..e69bc8ea 100644 --- a/pyperf/_collect_metadata.py +++ b/pyperf/_collect_metadata.py @@ -11,8 +11,11 @@ resource = None try: - # Optional dependency - import psutil + from pyperf._utils import USE_PSUTIL + if not USE_PSUTIL: + psutil = None + else: + import psutil except ImportError: psutil = None diff --git a/pyperf/_cpu_utils.py b/pyperf/_cpu_utils.py index ea230109..f810df25 100644 --- a/pyperf/_cpu_utils.py +++ b/pyperf/_cpu_utils.py @@ -2,11 +2,13 @@ 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, USE_PSUTIL try: - # Optional dependency - import psutil + if not USE_PSUTIL: + psutil = None + else: + import psutil except ImportError: psutil = None @@ -152,7 +154,10 @@ def set_cpu_affinity(cpus): return True try: - import psutil + if not USE_PSUTIL: + return + else: + import psutil except ImportError: return @@ -166,7 +171,10 @@ def set_cpu_affinity(cpus): def set_highest_priority(): try: - import psutil + if not USE_PSUTIL: + return + else: + import psutil except ImportError: return diff --git a/pyperf/_psutil_memory.py b/pyperf/_psutil_memory.py index f56cfb4a..ca6776ed 100644 --- a/pyperf/_psutil_memory.py +++ b/pyperf/_psutil_memory.py @@ -1,6 +1,10 @@ import os try: - import psutil + from pyperf._utils import USE_PSUTIL + if not USE_PSUTIL: + raise ImportError + else: + import psutil except ImportError: raise ImportError('psutil is not installed') import threading diff --git a/pyperf/_utils.py b/pyperf/_utils.py index a5ff155f..87bb1a7f 100644 --- a/pyperf/_utils.py +++ b/pyperf/_utils.py @@ -3,10 +3,14 @@ import os import statistics import sys +import sysconfig from shlex import quote as shell_quote # noqa from shutil import which - +# Currently there is a packaging issue for PEP-703, +# Until then psutil is disabled as a workaround. +# See: https://github.com/python/cpython/issues/116024 +USE_PSUTIL = not bool(sysconfig.get_config_var('Py_GIL_DISABLED')) MS_WINDOWS = (sys.platform == 'win32') MAC_OS = (sys.platform == 'darwin')