-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSError: [WinError 0] from QueryFullProcessImageNameW #1662
Comments
It turns out the fix was about Windows XP [1], so this is a new problem.
Fixed in efaa9e0. |
Do you guys know when the new version having this fix will be coming out? 🤔 |
|
Thanks for the command @giampaolo, but I just installed the new 5.7.0 psutil wheel and I am still having the same error 😞
|
Mmm I don't see how that can happen. I suspect that you're still using the old installation. Try |
I am working in a fresh virtual environment and sort of the trace points at _pswindows.py:759 which matches whatever is on master. 🤔 ... I don't see how I can be using an old installation unless I am missing something. |
One more update, I started to go back psutil versions and installing 5.5.1 works fine. I don't see any error. The moment I went to 5.6.0, I started to get the
Not sure if this helps to narrow things down, but I think I can workaround it like this in the meantime. |
Sometimes the compiled psutil/psutil/_psutil_windows.c Lines 468 to 471 in 994c429
The best thing you can do is install Visual Studio, put some debugging printf() s in the C code and see what happens:https://github.com/giampaolo/psutil/blob/master/INSTALL.rst#windows |
So I ended up modifying those lines as follows static PyObject *
psutil_proc_exe(PyObject *self, PyObject *args) {
DWORD pid;
HANDLE hProcess;
wchar_t exe[MAX_PATH];
unsigned int size = sizeof(exe);
if (! PyArg_ParseTuple(args, _Py_PARSE_PID, &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (NULL == hProcess)
return NULL;
memset(exe, 0, MAX_PATH);
if (QueryFullProcessImageNameW(hProcess, 0, exe, &size) == 0) {
// https://github.com/giampaolo/psutil/issues/1662
DWORD err_ret = GetLastError();
int bufferSize = WideCharToMultiByte(CP_UTF8, 0, exe, -1, NULL, 0, NULL, NULL);
char *utfString = (char*)malloc(bufferSize);
WideCharToMultiByte(CP_UTF8, 0, exe, -1, utfString, bufferSize, NULL, NULL);
if (err_ret == 0)
AccessDenied("QueryFullProcessImageNameW (forced EPERM)");
else
PyErr_MySetFromOSErrnoWithSyscall("QueryFullProcessImageNameW", err_ret, utfString, pid);
CloseHandle(hProcess);
return NULL;
}
CloseHandle(hProcess);
return PyUnicode_FromWideChar(exe, wcslen(exe));
} Where the code is printing in Looking at the new error, I have the following message: err_ret is 31, and based on https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-, 31 is:
Do you know what that means? 🤔 Am I looking at the right place? As an additional step, I enabled the Audit Process Tracking Security Policy to figure out what was the process that it was complaining about. It is our own program that we are starting, but based on Event Viewer. Our program is exiting correctly and gracefully:
|
#1677 has implicitly fixed this issue. |
#1677 indeed fixes our issue. We no longer see the error. Thanks @giampaolo 😄 |
I occasionally see this with psutil 5.6.7:
I haven't figured out how to reproduce it (I see it happening in scripts, but whatever process caused it has gone by the time I try to get more info out). It looks like QueryFullProcessImageNameW isn't always setting error info properly on failure, though, which then means the error isn't being translated to a psutil error.
I'm not sure there's anything you can reasonable do about this, but I thought you might like to be aware of it.
The text was updated successfully, but these errors were encountered: