From d090aac2ce9aa46ee469d4c0c14fc21061b78d72 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sat, 2 May 2020 15:32:17 +0200 Subject: Enhance Process repr and add exit code Show exit code if wait() was used and also use cached name if name() fails. --- psutil/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'psutil/__init__.py') diff --git a/psutil/__init__.py b/psutil/__init__.py index b03ffaee..411c6395 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -396,18 +396,22 @@ class Process(object): except AttributeError: info = {} # Python 2.6 info["pid"] = self.pid + if self._name: + info['name'] = self._name with self.oneshot(): try: info["name"] = self.name() info["status"] = self.status() - if self._create_time: - info['started'] = _pprint_secs(self._create_time) except ZombieProcess: info["status"] = "zombie" except NoSuchProcess: info["status"] = "terminated" except AccessDenied: pass + if self._exitcode not in (_SENTINEL, None): + info["exitcode"] = self._exitcode + if self._create_time: + info['started'] = _pprint_secs(self._create_time) return "%s.%s(%s)" % ( self.__class__.__module__, self.__class__.__name__, -- cgit v1.2.1