diff --git a/psutil/arch/bsd/proc.c b/psutil/arch/bsd/proc.c index 1644957ea..959b28ee0 100644 --- a/psutil/arch/bsd/proc.c +++ b/psutil/arch/bsd/proc.c @@ -449,6 +449,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) { psutil_debug( "open_files() returned ESRCH for PID 0; forcing `return []`" ); + PyErr_Clear(); return py_retlist; } #else diff --git a/psutil/arch/openbsd/proc.c b/psutil/arch/openbsd/proc.c index 9b4593c3e..bf4015be4 100644 --- a/psutil/arch/openbsd/proc.c +++ b/psutil/arch/openbsd/proc.c @@ -288,12 +288,14 @@ psutil_proc_num_fds(PyObject *self, PyObject *args) { return NULL; freep = kinfo_getfile(pid, &cnt); + if (freep == NULL) { #if defined(PSUTIL_OPENBSD) if ((pid == 0) && (errno == ESRCH)) { psutil_debug( "num_fds() returned ESRCH for PID 0; forcing `return 0`" ); + PyErr_Clear(); return Py_BuildValue("i", 0); } #endif