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 5 commits
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
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.
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
8 changes: 7 additions & 1 deletion pyperf/_collect_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
resource = None

try:
from pyperf._utils import FREE_THREADING
# Optional dependency
import psutil
# Currently there is a packaging issue for PEP-703,
# Until then psutil is disabled as a workaround.
if FREE_THREADING:
psutil = None
else:
import psutil
except ImportError:
psutil = None

Expand Down
23 changes: 19 additions & 4 deletions pyperf/_cpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
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, FREE_THREADING

try:
# Optional dependency
import psutil
# Currently there is a packaging issue for PEP-703,
# Until then psutil is disabled as a workaround.
if FREE_THREADING:
corona10 marked this conversation as resolved.
Show resolved Hide resolved
psutil = None
else:
import psutil
except ImportError:
psutil = None

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

try:
import psutil
# Currently there is a packaging issue for PEP-703,
# Until then psutil is disabled as a workaround.
if FREE_THREADING:
return
else:
import psutil
except ImportError:
return

Expand All @@ -166,7 +176,12 @@ def set_cpu_affinity(cpus):

def set_highest_priority():
try:
import psutil
# Currently there is a packaging issue for PEP-703,
# Until then psutil is disabled as a workaround.
if FREE_THREADING:
return
else:
import psutil
except ImportError:
return

Expand Down
8 changes: 7 additions & 1 deletion pyperf/_psutil_memory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
try:
import psutil
from pyperf._utils import FREE_THREADING
# Currently there is a packaging issue for PEP-703,
# Until then psutil is disabled as a workaround.
if 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


FREE_THREADING = 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
Loading