From fe68b30dacec3255b023fcefac5c9095d96a692f Mon Sep 17 00:00:00 2001 From: wiggin15 Date: Mon, 13 Nov 2017 00:38:12 +0200 Subject: Move exceptions to separate file (#1174) --- psutil/_psosx.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'psutil/_psosx.py') diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 8093e814..c2a8b3af 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -23,6 +23,10 @@ from ._common import parse_environ_block from ._common import sockfam_to_enum from ._common import socktype_to_enum from ._common import usage_percent +from ._exceptions import NoSuchProcess +from ._exceptions import ZombieProcess +from ._exceptions import AccessDenied +from ._exceptions import TimeoutExpired __extra__all__ = [] @@ -84,12 +88,6 @@ pidtaskinfo_map = dict( volctxsw=7, ) -# these get overwritten on "import psutil" from the __init__.py file -NoSuchProcess = None -ZombieProcess = None -AccessDenied = None -TimeoutExpired = None - # ===================================================================== # --- named tuples -- cgit v1.2.1 From 100391f880ef2a2c5b124bba4b0722623f3edb3e Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 12 Nov 2017 23:41:30 +0100 Subject: sort imports by name --- psutil/_psosx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'psutil/_psosx.py') diff --git a/psutil/_psosx.py b/psutil/_psosx.py index c2a8b3af..583ed355 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -23,10 +23,10 @@ from ._common import parse_environ_block from ._common import sockfam_to_enum from ._common import socktype_to_enum from ._common import usage_percent -from ._exceptions import NoSuchProcess -from ._exceptions import ZombieProcess from ._exceptions import AccessDenied +from ._exceptions import NoSuchProcess from ._exceptions import TimeoutExpired +from ._exceptions import ZombieProcess __extra__all__ = [] -- cgit v1.2.1 From 40573cbe58407a3f8dfcb0c3b71237444b10fc0a Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 13 Nov 2017 00:00:30 +0100 Subject: #1174: use TimeoutExpired in wait_pid() --- psutil/_psosx.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'psutil/_psosx.py') diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 583ed355..e9b6ed82 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -25,7 +25,6 @@ from ._common import socktype_to_enum from ._common import usage_percent from ._exceptions import AccessDenied from ._exceptions import NoSuchProcess -from ._exceptions import TimeoutExpired from ._exceptions import ZombieProcess @@ -500,10 +499,7 @@ class Process(object): @wrap_exceptions def wait(self, timeout=None): - try: - return _psposix.wait_pid(self.pid, timeout) - except _psposix.TimeoutExpired: - raise TimeoutExpired(timeout, self.pid, self._name) + return _psposix.wait_pid(self.pid, timeout, self._name) @wrap_exceptions def nice_get(self): -- cgit v1.2.1 From 3a3598e433adec73e2a9c4d5f08e658516fb1d32 Mon Sep 17 00:00:00 2001 From: wiggin15 Date: Sun, 19 Nov 2017 20:06:18 +0200 Subject: OSX: implement sensors_battery (#1177) --- psutil/_psosx.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'psutil/_psosx.py') diff --git a/psutil/_psosx.py b/psutil/_psosx.py index e9b6ed82..9fa7716d 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -207,6 +207,29 @@ def disk_partitions(all=False): return retlist +# ===================================================================== +# --- sensors +# ===================================================================== + + +def sensors_battery(): + """Return battery information. + """ + try: + percent, minsleft, power_plugged = cext.sensors_battery() + except NotImplementedError: + # no power source - return None according to interface + return None + power_plugged = power_plugged == 1 + if power_plugged: + secsleft = _common.POWER_TIME_UNLIMITED + elif minsleft == -1: + secsleft = _common.POWER_TIME_UNKNOWN + else: + secsleft = minsleft * 60 + return _common.sbattery(percent, secsleft, power_plugged) + + # ===================================================================== # --- network # ===================================================================== -- cgit v1.2.1 From 98f0e70fdc7f44cc982f7496557dcdc31a9f99e6 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 4 Dec 2017 13:50:38 +0100 Subject: Fix OSX pid 0 bug (#1187) * debug * change travis conf * more debug info * work around pid 0 on osx * fix pid 0 bug * skip failing test on OSX + TRAVIS which started failing all of the sudden * skip failing test on osx + travis --- psutil/_psosx.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'psutil/_psosx.py') diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 9fa7716d..4c97af71 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -301,7 +301,23 @@ def users(): # ===================================================================== -pids = cext.pids +def pids(): + ls = cext.pids() + if 0 not in ls: + # On certain OSX versions pids() C doesn't return PID 0 but + # "ps" does and the process is querable via sysctl(): + # https://travis-ci.org/giampaolo/psutil/jobs/309619941 + try: + Process(0).create_time() + except NoSuchProcess: + return False + except AccessDenied: + ls.append(0) + else: + ls.append(0) + return ls + + pid_exists = _psposix.pid_exists -- cgit v1.2.1 From 090ae20078e7135fa0fe95db2b83366079da9802 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Thu, 7 Dec 2017 13:13:36 +0100 Subject: what a stupid bug! (#1190) --- psutil/_psosx.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'psutil/_psosx.py') diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 4c97af71..308756a8 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -309,12 +309,11 @@ def pids(): # https://travis-ci.org/giampaolo/psutil/jobs/309619941 try: Process(0).create_time() + ls.append(0) except NoSuchProcess: - return False + pass except AccessDenied: ls.append(0) - else: - ls.append(0) return ls -- cgit v1.2.1