Skip to content
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

Introduce PSUTIL_DEBUG mode (via env var) #1173

Closed
giampaolo opened this issue Nov 12, 2017 · 0 comments
Closed

Introduce PSUTIL_DEBUG mode (via env var) #1173

giampaolo opened this issue Nov 12, 2017 · 0 comments

Comments

@giampaolo
Copy link
Owner

giampaolo commented Nov 12, 2017

This occurred to me while debugging #1152. It would be extremely useful to be able to run psutil in DEBUG mode and print useful messages on stderr in order to debug nasty issues. In order to use it one would have to start python like this:

PSUTIL_DEBUG=1 python script.py

On Windows:

set PSUTIL_DEBUG=1 && C:\Python36\python.exe script.py

Something like this will likely be used only for error conditions, before raising an exception, and never for informational logging. Currently if a C function body has 2 syscalls, both raising OSError, the Python exception does not tell you which one failed. With this in place we can do:

if (! syscall1()) {
    debug("syscall1 failed");
    return PyErr_SetFromErrno(PyExc_OSError);
}
if (! syscall2()) {
    debug("syscall2 failed");
    return PyErr_SetFromErrno(PyExc_OSError);
}

...and the traceback will look like this:

psutil-debug> syscall2 failed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory: 'foo'

This will make users able to submit better reports on the bug tracker. Unit tests and CI services will likely have PSUTIL_DEBUG enabled by default for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant