From 0b93503cb98c0abb37030639c3b1278ac52a47ee Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 14 Oct 2024 20:14:42 +0200 Subject: [PATCH] fix open_files --- psutil/_psbsd.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index 5f01b5407..d40d31c40 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -911,7 +911,14 @@ def _not_implemented(self): @wrap_exceptions def open_files(self): """Return files opened by process as a list of namedtuples.""" - rawlist = cext.proc_open_files(self.pid) + if OPENBSD and self.pid == 0: + try: + rawlist = cext.proc_open_files(self.pid) + except ProcessLookupError: + return [] + else: + rawlist = cext.proc_open_files(self.pid) + return [_common.popenfile(path, fd) for path, fd in rawlist] else: @@ -930,9 +937,7 @@ def num_fds(self): except ProcessLookupError: return 0 elif NETBSD: - ret = cext.proc_num_fds(self.pid) self._assert_alive() - return ret return cext.proc_num_fds(self.pid)