Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-174: Support free-threading CPython by disabling psutil related fe… #175

Merged
merged 7 commits into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a link to the issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which link? PEP 703?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current blocker is pypa/packaging#755, but there's ~3 more steps needed after that too (update packaging in pip, release pip, update pip in CPython).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue describing why pyperf cannot use psutil on a Python Free Threading build.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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
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
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
@@ -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
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')
corona10 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down