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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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.

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:
corona10 marked this conversation as resolved.
Show resolved Hide resolved
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'))
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to remove IS_: just FREE_THREADING.

MS_WINDOWS = (sys.platform == 'win32')
MAC_OS = (sys.platform == 'darwin')
corona10 marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Loading