Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling _set_debug(True) doesn't import inspect #2078

Closed
zooba opened this issue Feb 23, 2022 · 0 comments
Closed

Calling _set_debug(True) doesn't import inspect #2078

zooba opened this issue Feb 23, 2022 · 0 comments
Labels

Comments

@zooba
Copy link
Contributor

zooba commented Feb 23, 2022

When the tests enable debug messages, they call this function and pass True:

psutil/psutil/__init__.py

Lines 2349 to 2355 in dd57b9a

def _set_debug(value):
"""Enable or disable PSUTIL_DEBUG option, which prints debugging
messages to stderr.
"""
import psutil._common
psutil._common.PSUTIL_DEBUG = bool(value)
_psplatform.cext.set_debug(bool(value))

However, if the environment variable wasn't already set, the import of inspect was skipped and any attempt to display a debug message will fail.

psutil/psutil/_common.py

Lines 46 to 48 in dd57b9a

PSUTIL_DEBUG = bool(os.getenv('PSUTIL_DEBUG', 0))
if PSUTIL_DEBUG:
import inspect

The import of inspect should probably just be done inside the debug function.

@zooba zooba added the bug label Feb 23, 2022
zooba added a commit to zooba/psutil that referenced this issue Feb 23, 2022
This avoids issues when debug messages are enabled at runtime, as the module-level import may have been skipped.
zooba added a commit to zooba/psutil that referenced this issue Feb 23, 2022
This avoids issues when debug messages are enabled at runtime, as the module-level import may have been skipped.

Signed-off-by: Steve Dower <steve.dower@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant