diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2021-10-03 21:21:43 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2021-10-03 21:21:43 +0200 |
commit | 88055533025aa92f8c607e05263fc565f8b929ab (patch) | |
tree | 4d4fc0ab8d70b0c3f92ecbc488797a2920f56720 | |
parent | 98915102cc97869b8418d38088a1dcb59b931ffe (diff) | |
download | psutil-88055533025aa92f8c607e05263fc565f8b929ab.tar.gz |
fix #1919 / Linux: sensors_battery() may raise TypeError on PureOS
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | psutil/_common.py | 1 | ||||
-rw-r--r-- | psutil/_pslinux.py | 5 |
3 files changed, 5 insertions, 2 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index db0e4261..adcaaa45 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -27,6 +27,7 @@ XXXX-XX-XX - 1904_: [Windows] OpenProcess fails with ERROR_SUCCESS due to GetLastError() called after sprintf(). (patch by alxchk) - 1913_: [Linux] wait_procs seemingly ignoring timeout, TimeoutExpired thrown +- 1919_: [Linux] sensors_battery() can raise TypeError on PureOS. - 1921_: [Windows] psutil.swap_memory() shows committed memory instead of swap - 1948_: Process' memoize_when_activated decorator was not thread-safe. (patch by Xuehai Pan) diff --git a/psutil/_common.py b/psutil/_common.py index 306301ed..e83568b5 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -431,7 +431,6 @@ def memoize_when_activated(fun): >>> foo() >>> """ - @functools.wraps(fun) def wrapper(self): try: diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 640a0f3d..3afe6c65 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1390,7 +1390,10 @@ def sensors_battery(): for path in paths: ret = cat(path, fallback=null) if ret != null: - return int(ret) if ret.isdigit() else ret + try: + return int(ret) + except ValueError: + return ret return None bats = [x for x in os.listdir(POWER_SUPPLY_PATH) if x.startswith('BAT') or |