Skip to content

Commit

Permalink
Merge branch 'master' into thread-safe-globals
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jul 31, 2023
2 parents c609d24 + 1fe0497 commit 79ba77c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ jobs:
python-version: 3.11

- name: Create wheels + run tests
uses: pypa/cibuildwheel@v2.11.2
uses: pypa/cibuildwheel@v2.14.1
env:
CIBW_ARCHS: "${{ matrix.archs }}"
CIBW_PRERELEASE_PYTHONS: True

- name: Upload wheels
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -110,6 +111,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 @@ -21,6 +21,7 @@ XXXX-XX-XX
Klausner)
- 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
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,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: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ def net_io_counters(pernic=False, nowrap=True):
and wrap (restart from 0) and add "old value" to "new value" so that
the returned numbers will always be increasing or remain the same,
but never decrease.
"disk_io_counters.cache_clear()" can be used to invalidate the
"net_io_counters.cache_clear()" can be used to invalidate the
cache.
"""
rawdict = _psplatform.net_io_counters()
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
6 changes: 3 additions & 3 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,12 +1059,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
4 changes: 2 additions & 2 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,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 @@ -388,7 +388,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

0 comments on commit 79ba77c

Please sign in to comment.