From 614ecab7ae870138275a6dd56e4b0fc6bed42b58 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 5 Aug 2016 18:48:55 -0700 Subject: [PATCH] #799 / windows / cpu_times: add ionice() support --- psutil/_psutil_windows.c | 10 +++------- psutil/_pswindows.py | 3 ++- scripts/internal/bench_oneshot.py | 3 ++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 02a16a8cb..b023e65ab 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -1944,27 +1944,23 @@ psutil_proc_priority_set(PyObject *self, PyObject *args) { static PyObject * psutil_proc_io_priority_get(PyObject *self, PyObject *args) { long pid; - HANDLE hProcess; + unsigned long handle; PULONG IoPriority; _NtQueryInformationProcess NtQueryInformationProcess = (_NtQueryInformationProcess)GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess"); - if (! PyArg_ParseTuple(args, "l", &pid)) - return NULL; - hProcess = psutil_handle_from_pid(pid); - if (hProcess == NULL) + if (! PyArg_ParseTuple(args, "lk", &pid, &handle)) return NULL; NtQueryInformationProcess( - hProcess, + (HANDLE)handle, ProcessIoPriority, &IoPriority, sizeof(ULONG), NULL ); - CloseHandle(hProcess); return Py_BuildValue("i", IoPriority); } diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index b575a85e3..88a1f9c99 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -803,7 +803,8 @@ def nice_set(self, value): if hasattr(cext, "proc_io_priority_get"): @wrap_exceptions def ionice_get(self): - return cext.proc_io_priority_get(self.pid) + with self.handle_ctx() as handle: + return cext.proc_io_priority_get(self.pid, handle) @wrap_exceptions def ionice_set(self, value, _): diff --git a/scripts/internal/bench_oneshot.py b/scripts/internal/bench_oneshot.py index e818cc585..73504e02a 100755 --- a/scripts/internal/bench_oneshot.py +++ b/scripts/internal/bench_oneshot.py @@ -77,10 +77,11 @@ names = ( 'cpu_percent', 'cpu_times', - 'num_handles', + 'ionice', 'memory_info', 'memory_percent', 'nice', + 'num_handles', ) else: raise RuntimeError("platform %r not supported" % sys.platform)