Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Merge branch 'giampaolo-master'
Browse files Browse the repository at this point in the history
* giampaolo-master:
  add black opt to make lines more compact
  giampaolo#2366 [Windows]: log debug message when using slower process APIs
  Linux: skip offline cpu cores in cpu_freq (giampaolo#2376)
  fix py2 failure
  update style to latest black ver
  chore: update cibuildwheel on windows (giampaolo#2370)
  use unicode literals u"" instead of u("")
  make install-pip: fix installation on python 2
  more ruff rules
  adapt to new ruff config directives
  update CREDITS + mention @c0m4r for sponsorship (thanks!)
  Include net/if.h before net/if_dl.h (giampaolo#2361)
  pre-release
  fix failing tests
  refac t
  • Loading branch information
ddelange committed Feb 27, 2024
2 parents 4d26bd4 + eec5dae commit 149cd6e
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
if: matrix.archs == 'aarch64'

- name: Create wheels + run tests
uses: pypa/cibuildwheel@v2.16.2
uses: pypa/cibuildwheel@v2.16.5
with:
config-file: "./cibuildwheel.toml"
env:
Expand Down
8 changes: 8 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,11 @@ I: 2010
N: Oliver Tomé
W: https://github.com/snom3ad
I: 2222

N: Ryan Carsten Schmidt
W: https://github.com/ryandesign
I: 2361

N: Shade Gladden
W: https://github.com/shadeyg56
I: 2376
18 changes: 16 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*

5.9.8 (IN DEVELOPMENT)
5.9.9 (IN DEVELOPMENT)
======================

**Enhancements**

- 2366_, [Windows]: log debug message when using slower process APIs.

**Bug fixes**

- 2360_, [macOS]: can't compile on macOS < 10.13. (patch by Ryan Schmidt)
- 2254_, [Linux]: offline cpus raise NotImplementedError in cpu_freq() (patch by Shade Gladden)

5.9.8
=====

2024-01-19

**Enhancements**

- 2343_, [FreeBSD]: filter `net_connections()`_ returned list in C instead of
Python, and avoid to retrieve unnecessary connection types unless explicitly
asked. E.g., on an IDLE system with few IPv6 connections this will run around
Expand All @@ -19,7 +33,7 @@
It could either leak memory or core dump.
- 2340_, [NetBSD]: if process is terminated, `Process.cwd()`_ will return an
empty string instead of raising `NoSuchProcess`_.
- 2345_, [Linux]: fix compilation on older compiler missing DUPLEX_UNKNOWN
- 2345_, [Linux]: fix compilation on older compiler missing DUPLEX_UNKNOWN.
- 2222_, [macOS]: `cpu_freq()` now returns fixed values for `min` and `max`
frequencies in all Apple Silicon chips.

Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ install-pip: ## Install pip (no-op if already installed).
@$(PYTHON) -c \
"import sys, ssl, os, pkgutil, tempfile, atexit; \
sys.exit(0) if pkgutil.find_loader('pip') else None; \
pyexc = 'from urllib.request import urlopen' if sys.version_info[0] == 3 else 'from urllib2 import urlopen'; \
PY3 = sys.version_info[0] == 3; \
pyexc = 'from urllib.request import urlopen' if PY3 else 'from urllib2 import urlopen'; \
exec(pyexc); \
ctx = ssl._create_unverified_context() if hasattr(ssl, '_create_unverified_context') else None; \
url = 'https://bootstrap.pypa.io/pip/2.7/get-pip.py' if not PY3 else 'https://bootstrap.pypa.io/get-pip.py'; \
kw = dict(context=ctx) if ctx else {}; \
req = urlopen('https://bootstrap.pypa.io/get-pip.py', **kw); \
req = urlopen(url, **kw); \
data = req.read(); \
f = tempfile.NamedTemporaryFile(suffix='.py'); \
atexit.register(f.close); \
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Supporters
<a href="https://github.com/robusta-dev"><img height="40" width="40" title="Robusta" src="https://avatars.githubusercontent.com/u/82757710?s=200&v=4" /></a>
<a href="https://github.com/JeremyGrosser"><img height="40" width="40" title="JeremyGrosser" src="https://avatars.githubusercontent.com/u/2151?v=4" /></a>
<a href="https://github.com/getsentry"><img height="40" width="40" title="getsentry" src="https://avatars.githubusercontent.com/u/1396951?s=200&v=4" /></a>
<a href="https://github.com/c0m4r"><img height="40" width="40" title="c0m4r" src="https://avatars.githubusercontent.com/u/6292788?v=4" /></a>

</div>
<sup><a href="https://github.com/sponsors/giampaolo">add your avatar</a></sup>
Expand Down
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
#

# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# psutil documentation build configuration file, created by
# sphinx-quickstart on Wed Oct 19 21:54:30 2016.
#
Expand Down
6 changes: 5 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2650,9 +2650,13 @@ PyPy3.
Timeline
========

- 2024-01-19:
`5.9.8 <https://pypi.org/project/psutil/5.9.8/#files>`__ -
`what's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#598>`__ -
`diff <https://github.com/giampaolo/psutil/compare/release-5.9.7...release-5.9.8#files_bucket>`__
- 2023-12-17:
`5.9.7 <https://pypi.org/project/psutil/5.9.7/#files>`__ -
`what's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#596>`__ -
`what's new <https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#597>`__ -
`diff <https://github.com/giampaolo/psutil/compare/release-5.9.6...release-5.9.7#files_bucket>`__
- 2023-10-15:
`5.9.6 <https://pypi.org/project/psutil/5.9.6/#files>`__ -
Expand Down
8 changes: 1 addition & 7 deletions psutil/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# builtins
"long", "range", "super", "unicode", "basestring",
# literals
"u", "b",
"b",
# collections module
"lru_cache",
# shutil module
Expand All @@ -47,9 +47,6 @@
basestring = str
range = range

def u(s):
return s

def b(s):
return s.encode("latin-1")

Expand All @@ -59,9 +56,6 @@ def b(s):
unicode = unicode
basestring = basestring

def u(s):
return unicode(s, "unicode_escape")

def b(s):
return s

Expand Down
15 changes: 11 additions & 4 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

# fmt: off
__extra__all__ = [
#
'PROCFS_PATH',
# io prio constants
"IOPRIO_CLASS_NONE", "IOPRIO_CLASS_RT", "IOPRIO_CLASS_BE",
Expand Down Expand Up @@ -780,6 +779,13 @@ def cpu_freq():
# https://github.com/giampaolo/psutil/issues/1071
curr = bcat(pjoin(path, "cpuinfo_cur_freq"), fallback=None)
if curr is None:
online_path = (
"/sys/devices/system/cpu/cpu{}/online".format(i)
)
# if cpu core is offline, set to all zeroes
if cat(online_path, fallback=None) == "0\n":
ret.append(_common.scpufreq(0.0, 0.0, 0.0))
continue
msg = "can't find current frequency file"
raise NotImplementedError(msg)
curr = int(curr) / 1000
Expand Down Expand Up @@ -1355,7 +1361,7 @@ def disk_partitions(all=False):
if device in ("/dev/root", "rootfs"):
device = RootFsDeviceFinder().find() or device
if not all:
if device == '' or fstype not in fstypes:
if not device or fstype not in fstypes:
continue
maxfile = maxpath = None # set later
ntuple = _common.sdiskpart(
Expand Down Expand Up @@ -2101,7 +2107,7 @@ def get_blocks(lines, current_block):
path
):
path = path[:-10]
ls.append((
item = (
decode(addr),
decode(perms),
path,
Expand All @@ -2115,7 +2121,8 @@ def get_blocks(lines, current_block):
data.get(b'Referenced:', 0),
data.get(b'Anonymous:', 0),
data.get(b'Swap:', 0),
))
)
ls.append(item)
return ls

@wrap_exceptions
Expand Down
8 changes: 6 additions & 2 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ def virtual_memory():
"""System virtual memory as a namedtuple."""
mem = cext.virtual_mem()
totphys, availphys, totsys, availsys = mem
#
total = totphys
avail = availphys
free = availphys
Expand Down Expand Up @@ -515,7 +514,7 @@ def win_service_get(name):
return service


class WindowsService:
class WindowsService: # noqa: PLW1641
"""Represents an installed Windows service."""

def __init__(self, name, display_name):
Expand Down Expand Up @@ -865,6 +864,7 @@ def _get_raw_meminfo(self):
if is_permission_err(err):
# TODO: the C ext can probably be refactored in order
# to get this from cext.proc_info()
debug("attempting memory_info() fallback (slower)")
info = self._proc_info()
return (
info[pinfo_map['num_page_faults']],
Expand Down Expand Up @@ -992,6 +992,7 @@ def create_time(self):
return created
except OSError as err:
if is_permission_err(err):
debug("attempting create_time() fallback (slower)")
return self._proc_info()[pinfo_map['create_time']]
raise

Expand All @@ -1015,6 +1016,7 @@ def cpu_times(self):
except OSError as err:
if not is_permission_err(err):
raise
debug("attempting cpu_times() fallback (slower)")
info = self._proc_info()
user = info[pinfo_map['user_time']]
system = info[pinfo_map['kernel_time']]
Expand Down Expand Up @@ -1101,6 +1103,7 @@ def io_counters(self):
except OSError as err:
if not is_permission_err(err):
raise
debug("attempting io_counters() fallback (slower)")
info = self._proc_info()
ret = (
info[pinfo_map['io_rcount']],
Expand Down Expand Up @@ -1160,6 +1163,7 @@ def num_handles(self):
return cext.proc_num_handles(self.pid)
except OSError as err:
if is_permission_err(err):
debug("attempting num_handles() fallback (slower)")
return self._proc_info()[pinfo_map['num_handles']]
raise

Expand Down
2 changes: 1 addition & 1 deletion psutil/arch/osx/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
// https://github.com/giampaolo/psutil/blame/efd7ed3/psutil/_psutil_osx.c

#include <Python.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <net/if.h>

#include "../../_psutil_common.h"

Expand Down
20 changes: 8 additions & 12 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
from psutil._compat import FileNotFoundError
from psutil._compat import range
from psutil._compat import super
from psutil._compat import u
from psutil._compat import unicode
from psutil._compat import which

Expand Down Expand Up @@ -192,7 +191,7 @@ def macos_version():
TESTFN_PREFIX = '$psutil-%s-' % os.getpid()
else:
TESTFN_PREFIX = '@psutil-%s-' % os.getpid()
UNICODE_SUFFIX = u("-ƒőő")
UNICODE_SUFFIX = u"-ƒőő"
# An invalid unicode string.
if PY3:
INVALID_UNICODE_SUFFIX = b"f\xc0\x80".decode('utf8', 'surrogateescape')
Expand Down Expand Up @@ -358,7 +357,7 @@ def wrapper(*args, **kwargs):

@_reap_children_on_err
def spawn_testproc(cmd=None, **kwds):
"""Creates a python subprocess which does nothing for 60 secs and
"""Create a python subprocess which does nothing for some secs and
return it as a subprocess.Popen instance.
If "cmd" is specified that is used instead of python.
By default stdin and stdout are redirected to /dev/null.
Expand All @@ -377,13 +376,13 @@ def spawn_testproc(cmd=None, **kwds):
CREATE_NO_WINDOW = 0x8000000
kwds.setdefault("creationflags", CREATE_NO_WINDOW)
if cmd is None:
testfn = get_testfn()
testfn = get_testfn(dir=os.getcwd())
try:
safe_rmpath(testfn)
pyline = (
"from time import sleep;"
"import time;"
+ "open(r'%s', 'w').close();" % testfn
+ "[sleep(0.1) for x in range(100)];" # 10 secs
+ "[time.sleep(0.1) for x in range(100)];" # 10 secs
)
cmd = [PYTHON_EXE, "-c", pyline]
sproc = subprocess.Popen(cmd, **kwds)
Expand Down Expand Up @@ -743,9 +742,9 @@ def wrapper(*args, **kwargs):
self.sleep()
continue
if PY3:
raise exc
raise exc # noqa: PLE0704
else:
raise
raise # noqa: PLE0704

# This way the user of the decorated function can change config
# parameters.
Expand All @@ -766,9 +765,6 @@ def wait_for_pid(pid):
if pid not in psutil.pids():
raise psutil.NoSuchProcess(pid)
psutil.Process(pid)
if WINDOWS:
# give it some more time to allow better initialization
time.sleep(0.01)


@retry(
Expand Down Expand Up @@ -1953,7 +1949,7 @@ def is_namedtuple(x):
"""Check if object is an instance of namedtuple."""
t = type(x)
b = t.__bases__
if len(b) != 1 or b[0] != tuple:
if len(b) != 1 or b[0] is not tuple:
return False
f = getattr(t, '_fields', None)
if not isinstance(f, tuple):
Expand Down
Loading

0 comments on commit 149cd6e

Please sign in to comment.