From 51eb1dae7bf96dcc7dae51641d5770fd0d99d0ac Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 30 Dec 2020 10:57:35 +0100 Subject: [PATCH] provide debug info in case of error for getloadavg() on Windows. See: https://github.com/nicolargo/glances/issues/1780 Signed-off-by: Giampaolo Rodola --- psutil/arch/windows/wmi.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/psutil/arch/windows/wmi.c b/psutil/arch/windows/wmi.c index f9a847d3b..5fad4053e 100644 --- a/psutil/arch/windows/wmi.c +++ b/psutil/arch/windows/wmi.c @@ -64,22 +64,28 @@ psutil_init_loadavg_counter(PyObject *self, PyObject *args) { HANDLE event; HANDLE waitHandle; - if ((PdhOpenQueryW(NULL, 0, &hQuery)) != ERROR_SUCCESS) - goto error; + if ((PdhOpenQueryW(NULL, 0, &hQuery)) != ERROR_SUCCESS) { + PyErr_Format(PyExc_RuntimeError, "PdhOpenQueryW failed"); + return NULL; + } s = PdhAddEnglishCounterW(hQuery, szCounterPath, 0, &hCounter); - if (s != ERROR_SUCCESS) - goto error; + if (s != ERROR_SUCCESS) { + PyErr_Format(PyExc_RuntimeError, "PdhAddEnglishCounterW failed"); + return NULL; + } event = CreateEventW(NULL, FALSE, FALSE, L"LoadUpdateEvent"); if (event == NULL) { - PyErr_SetFromWindowsErr(0); + PyErr_SetFromOSErrnoWithSyscall("CreateEventW"); return NULL; } s = PdhCollectQueryDataEx(hQuery, SAMPLING_INTERVAL, event); - if (s != ERROR_SUCCESS) - goto error; + if (s != ERROR_SUCCESS) { + PyErr_Format(PyExc_RuntimeError, "PdhCollectQueryDataEx failed"); + return NULL; + } ret = RegisterWaitForSingleObject( &waitHandle, @@ -91,15 +97,11 @@ psutil_init_loadavg_counter(PyObject *self, PyObject *args) { WT_EXECUTEDEFAULT); if (ret == 0) { - PyErr_SetFromWindowsErr(0); + PyErr_SetFromOSErrnoWithSyscall("RegisterWaitForSingleObject"); return NULL; } Py_RETURN_NONE; - -error: - PyErr_SetFromWindowsErr(0); - return NULL; }