summaryrefslogtreecommitdiff
path: root/psutil/_common.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2021-10-14 22:52:32 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2021-10-14 22:52:32 +0200
commite72438f08ac7aa93b33fddcb11298ece28d0150d (patch)
tree1a8b33a122c85f6deeaf11178ab138078c0a3bf5 /psutil/_common.py
parente91bae62e6e6ee9c3ad27c1fe3013f929309e1b0 (diff)
downloadpsutil-e72438f08ac7aa93b33fddcb11298ece28d0150d.tar.gz
Changes to debug() function:
* use str() if exception derives from OSError / EnvironmentError. This way we will print the file name (if it exists). * use repr() for any other exception * add tests for debug() function * backport contextlib.redirect_stderr Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Diffstat (limited to 'psutil/_common.py')
-rw-r--r--psutil/_common.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/psutil/_common.py b/psutil/_common.py
index a2b8bab6..6a2f38e1 100644
--- a/psutil/_common.py
+++ b/psutil/_common.py
@@ -837,7 +837,11 @@ if bool(os.getenv('PSUTIL_DEBUG', 0)):
fname, lineno, func_name, lines, index = inspect.getframeinfo(
inspect.currentframe().f_back)
if isinstance(msg, Exception):
- msg = "ignoring %s" % msg
+ if isinstance(msg, (OSError, IOError, EnvironmentError)):
+ # ...because str(exc) may contain info about the file name
+ msg = "ignoring %s" % msg
+ else:
+ msg = "ignoring %r" % msg
print("psutil-debug [%s:%s]> %s" % (fname, lineno, msg), # NOQA
file=sys.stderr)
else: