summaryrefslogtreecommitdiff
path: root/psutil/_common.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2021-10-26 01:04:48 +0200
committerGitHub <noreply@github.com>2021-10-26 01:04:48 +0200
commit0e15b4890a1d84f2aa800b745fdb0642d2ee966d (patch)
treedd6f3afc8f6f65d27f1389a950fc2cf64cf78943 /psutil/_common.py
parentd1cce5caed1b9c3809ed5e2f80c9c413afd0c09a (diff)
downloadpsutil-0e15b4890a1d84f2aa800b745fdb0642d2ee966d.tar.gz
PSUTIL_DEBUG: print file + line number for C ext modules (#2005)
Diffstat (limited to 'psutil/_common.py')
-rw-r--r--psutil/_common.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/psutil/_common.py b/psutil/_common.py
index 6a2f38e1..5e6dbb6d 100644
--- a/psutil/_common.py
+++ b/psutil/_common.py
@@ -41,6 +41,7 @@ else:
# can't take it from _common.py as this script is imported by setup.py
PY3 = sys.version_info[0] == 3
+PSUTIL_DEBUG = bool(os.getenv('PSUTIL_DEBUG', 0))
__all__ = [
# OS constants
@@ -829,11 +830,10 @@ def print_color(
SetConsoleTextAttribute(handle, DEFAULT_COLOR)
-if bool(os.getenv('PSUTIL_DEBUG', 0)):
- import inspect
-
- def debug(msg):
- """If PSUTIL_DEBUG env var is set, print a debug message to stderr."""
+def debug(msg):
+ """If PSUTIL_DEBUG env var is set, print a debug message to stderr."""
+ if PSUTIL_DEBUG:
+ import inspect
fname, lineno, func_name, lines, index = inspect.getframeinfo(
inspect.currentframe().f_back)
if isinstance(msg, Exception):
@@ -844,6 +844,3 @@ if bool(os.getenv('PSUTIL_DEBUG', 0)):
msg = "ignoring %r" % msg
print("psutil-debug [%s:%s]> %s" % (fname, lineno, msg), # NOQA
file=sys.stderr)
-else:
- def debug(msg):
- pass