diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-11-14 23:35:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-14 23:35:19 +0100 |
commit | 26c77800591a09718064d3bcea4b04c9a8544dd1 (patch) | |
tree | 0db7f1deffbea3d5e58ae125ee7f150a41bbc9a6 /psutil/_psutil_posix.c | |
parent | 4d3f5ba337c5a91efa642699cc96331718889b4f (diff) | |
download | psutil-26c77800591a09718064d3bcea4b04c9a8544dd1.tar.gz |
1173 debug mode (#1176)
* implement PSUTIL_DEBUG from C module
* update doc
* add psutil_debug() utility function
* update doc
* enable PSUTIL_DEBUG for tests
* update appveyor.yml
* change psutil_debug() signature so that it can accept variable num of args
* provide DEBUG info in psutil_raise_for_pid()
* properly print debug message
* do not print too much
Diffstat (limited to 'psutil/_psutil_posix.c')
-rw-r--r-- | psutil/_psutil_posix.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/psutil/_psutil_posix.c b/psutil/_psutil_posix.c index ea0fba53..76cf2db0 100644 --- a/psutil/_psutil_posix.c +++ b/psutil/_psutil_posix.c @@ -112,16 +112,21 @@ psutil_pid_exists(long pid) { * This will always set a Python exception and return NULL. */ int -psutil_raise_for_pid(long pid, char *msg) { +psutil_raise_for_pid(long pid, char *syscall_name) { // Set exception to AccessDenied if pid exists else NoSuchProcess. if (errno != 0) { + // Unlikely we get here. PyErr_SetFromErrno(PyExc_OSError); return 0; } - if (psutil_pid_exists(pid) == 0) + else if (psutil_pid_exists(pid) == 0) { + psutil_debug("%s syscall failed and PID %i no longer exists; " + "assume NoSuchProcess", syscall_name, pid); NoSuchProcess(); - else - PyErr_SetString(PyExc_RuntimeError, msg); + } + else { + PyErr_Format(PyExc_RuntimeError, "%s syscall failed", syscall_name); + } return 0; } |