diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-09 21:07:45 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-09 21:07:45 +0100 |
commit | 13cf7d7ab356233c3bb8dc34f1143e7bb0c2c088 (patch) | |
tree | e9a9ea8dd2654f5a19810c2653e0c47bab5bbf75 | |
parent | 72274ac02bd9b3b0c08acf861a2df223538b1c9e (diff) | |
download | psutil-13cf7d7ab356233c3bb8dc34f1143e7bb0c2c088.tar.gz |
fix #1650 [Linux] sensors_temperatures() no longer emit warnings on file not found (print debug msg instead)
-rw-r--r-- | psutil/_common.py | 12 | ||||
-rw-r--r-- | psutil/_pslinux.py | 4 | ||||
-rw-r--r-- | psutil/_pssunos.py | 4 |
3 files changed, 15 insertions, 5 deletions
diff --git a/psutil/_common.py b/psutil/_common.py index 729b1983..453c771d 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -7,7 +7,7 @@ # Note: this module is imported by setup.py so it should not import # psutil or third-party modules. -from __future__ import division +from __future__ import division, print_function import contextlib import errno @@ -66,7 +66,7 @@ __all__ = [ 'conn_tmap', 'deprecated_method', 'isfile_strict', 'memoize', 'parse_environ_block', 'path_exists_strict', 'usage_percent', 'supports_ipv6', 'sockfam_to_enum', 'socktype_to_enum', "wrap_numbers", - 'bytes2human', 'conn_to_ntuple', 'hilite', + 'bytes2human', 'conn_to_ntuple', 'hilite', 'debug', ] @@ -787,3 +787,11 @@ def hilite(s, ok=True, bold=False): if bold: attr.append('1') return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), s) + + +if bool(os.getenv('PSUTIL_DEBUG', 0)): + def debug(msg): + print("psutil-debug> " + msg, file=sys.stderr) +else: + def debug(msg): + pass diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 06935111..7348b3dc 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -26,6 +26,7 @@ from . import _psposix from . import _psutil_linux as cext from . import _psutil_posix as cext_posix from ._common import AccessDenied +from ._common import debug from ._common import decode from ._common import get_procfs_path from ._common import isfile_strict @@ -1253,8 +1254,7 @@ def sensors_temperatures(): path = os.path.join(base, 'type') unit_name = cat(path, binary=False) except (IOError, OSError, ValueError) as err: - warnings.warn("ignoring %r for file %r" % (err, path), - RuntimeWarning) + debug("ignoring %r for file %r" % (err, path)) continue trip_paths = glob.glob(base + '/trip_point*') diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index b82771ee..62362b89 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -19,6 +19,7 @@ from . import _psutil_posix as cext_posix from . import _psutil_sunos as cext from ._common import AccessDenied from ._common import AF_INET6 +from ._common import debug from ._common import get_procfs_path from ._common import isfile_strict from ._common import memoize_when_activated @@ -228,8 +229,9 @@ def disk_partitions(all=False): try: if not disk_usage(mountpoint).total: continue - except OSError: + except OSError as err: # https://github.com/giampaolo/psutil/issues/1674 + debug("skipping %r: %r" % (mountpoint, err)) continue ntuple = _common.sdiskpart(device, mountpoint, fstype, opts) retlist.append(ntuple) |