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

Commit

Permalink
Merge branch 'master' of https://github.com/giampaolo/psutil
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/giampaolo/psutil:
  fix var unbound (giampaolo#2245)
  Fix a dead link in the documentation (giampaolo#2280)
  chore: test with Python 3.12 (giampaolo#2270)
  chore(ci): fix linters job warning (giampaolo#2269)
  make flake8 happy
  add a fix-unittests make target to fix unit tests
  • Loading branch information
ddelange committed Jul 31, 2023
2 parents de61b89 + 88d33f7 commit 3b02735
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
config-file: "./cibuildwheel.toml"
env:
CIBW_ARCHS: ${{ matrix.archs }}
CIBW_PRERELEASE_PYTHONS: True

- name: Upload wheels
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -164,6 +165,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: 'Run linters'
run: |
# py3
Expand Down
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ XXXX-XX-XX
instead of OverflowError. (patch by Xuehai Pan)
- 2268_: ``bytes2human()`` utility function was unable to properly represent
negative values.
- 2252_: [Windows]: `psutil.disk_usage`_ fails on Python 3.12+. (patch by Matthieu Darbois)

5.9.5
=====
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PY3_DEPS = \
requests \
setuptools \
sphinx_rtd_theme \
teyit \
twine \
virtualenv \
wheel
Expand Down Expand Up @@ -225,9 +226,13 @@ fix-flake8: ## Run autopep8, fix some Python flake8 / pep8 issues.
fix-imports: ## Fix imports with isort.
@git ls-files '*.py' | xargs $(PYTHON) -m isort --jobs=${NUM_WORKERS}

fix-unittests: ## Fix unittest idioms.
@git ls-files '*test_*.py' | xargs $(PYTHON) -m teyit --show-stats

fix-all: ## Run all code fixers.
${MAKE} fix-flake8
${MAKE} fix-imports
${MAKE} fix-unittests

# ===================================================================
# GIT
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ Process class
fields are variable depending on the platform.
This method is useful to obtain a detailed representation of process
memory usage as explained
`here <http://bmaurer.blogspot.it/2006/03/memory-usage-with-smaps.html>`__
`here <https://web.archive.org/web/20180907232758/http://bmaurer.blogspot.com/2006/03/memory-usage-with-smaps.html>`__
(the most important value is "private" memory).
If *grouped* is ``True`` the mapped regions with the same *path* are
grouped together and the different memory fields are summed. If *grouped*
Expand Down
2 changes: 2 additions & 0 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def swap_memory():
percentswap = cext.swap_percent()
used = int(0.01 * percentswap * total)
else:
percentswap = 0.0
used = 0

free = total - used
percent = round(percentswap, 1)
return _common.sswap(total, used, free, percent, 0, 0)
Expand Down
29 changes: 25 additions & 4 deletions psutil/arch/windows/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ PyObject *
psutil_disk_usage(PyObject *self, PyObject *args) {
BOOL retval;
ULARGE_INTEGER _, total, free;

#if PY_MAJOR_VERSION <= 2
char *path;

if (PyArg_ParseTuple(args, "u", &path)) {
Expand All @@ -55,23 +57,42 @@ psutil_disk_usage(PyObject *self, PyObject *args) {

// on Python 2 we also want to accept plain strings other
// than Unicode
#if PY_MAJOR_VERSION <= 2
PyErr_Clear(); // drop the argument parsing error
if (PyArg_ParseTuple(args, "s", &path)) {
Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceEx(path, &_, &total, &free);
Py_END_ALLOW_THREADS
goto return_;
}
#endif

return NULL;

return_:
if (retval == 0)
return PyErr_SetFromWindowsErrWithFilename(0, path);
else
return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
#else
PyObject *py_path;
wchar_t *path;

if (!PyArg_ParseTuple(args, "U", &py_path)) {
return NULL;
}

path = PyUnicode_AsWideCharString(py_path, NULL);
if (path == NULL) {
return NULL;
}

Py_BEGIN_ALLOW_THREADS
retval = GetDiskFreeSpaceExW(path, &_, &total, &free);
Py_END_ALLOW_THREADS

PyMem_Free(path);

if (retval == 0)
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, 0, py_path);
#endif
return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart);
}


Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ def is_namedtuple(x):
f = getattr(t, '_fields', None)
if not isinstance(f, tuple):
return False
return all(type(n) == str for n in f)
return all(isinstance(n, str) for n in f)


if POSIX:
Expand Down
6 changes: 3 additions & 3 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,12 +1073,12 @@ def test_num_fds(self):
def test_num_ctx_switches(self):
p = psutil.Process()
before = sum(p.num_ctx_switches())
for _ in range(500000):
for _ in range(2):
time.sleep(0.05) # this shall ensure a context switch happens
after = sum(p.num_ctx_switches())
if after > before:
return
raise self.fail(
"num ctx switches still the same after 50.000 iterations")
raise self.fail("num ctx switches still the same after 2 iterations")

def test_ppid(self):
p = psutil.Process()
Expand Down
6 changes: 3 additions & 3 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_os_constants(self):

# assert all other constants are set to False
for name in names:
self.assertIs(getattr(psutil, name), False, msg=name)
self.assertFalse(getattr(psutil, name), msg=name)


class TestMemoryAPIs(PsutilTestCase):
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_cpu_times(self):
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
self.assertEqual(total, sum(times))
self.assertAlmostEqual(total, sum(times))
str(times)
# CPU times are always supposed to increase over time
# or at least remain the same and that's because time
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_per_cpu_times(self):
self.assertIsInstance(cp_time, float)
self.assertGreaterEqual(cp_time, 0.0)
total += cp_time
self.assertEqual(total, sum(times))
self.assertAlmostEqual(total, sum(times))
str(times)
self.assertEqual(len(psutil.cpu_times(percpu=True)[0]),
len(psutil.cpu_times(percpu=False)))
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,15 @@ def test_special_pid(self):
# that nothing strange happens
str(p)
p.username()
self.assertTrue(p.create_time() >= 0.0)
self.assertGreaterEqual(p.create_time(), 0.0)
try:
rss, vms = p.memory_info()[:2]
except psutil.AccessDenied:
# expected on Windows Vista and Windows 7
if not platform.uname()[1] in ('vista', 'win-7', 'win7'):
raise
else:
self.assertTrue(rss > 0)
self.assertGreater(rss, 0)

def test_send_signal(self):
p = psutil.Process(self.pid)
Expand Down

0 comments on commit 3b02735

Please sign in to comment.