Skip to content

Commit

Permalink
gh-174: Support free-threading CPython by disabling psutil related fe… (
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 authored Mar 6, 2024
1 parent c960443 commit 2065359
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -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)
---------------------------

Expand Down
7 changes: 5 additions & 2 deletions pyperf/_collect_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 13 additions & 5 deletions pyperf/_cpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

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 USE_PSUTIL
if not USE_PSUTIL:
raise ImportError
else:
import psutil
except ImportError:
raise ImportError('psutil is not installed')
import threading
Expand Down
6 changes: 5 additions & 1 deletion pyperf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 2065359

Please sign in to comment.