79310301

Date: 2024-12-26 19:38:27
Score: 0.5
Natty:
Report link

When your debug type is "debugpy" in the config, the debugging can be detected in sys.modules.

launch.json

{
    "configurations": [
        {
            "name": "Python Debugger: Module",
            "type": "debugpy",
            "request": "launch",
            "module": "app.main"
        }
    ]
}

app/main.py

def check_is_debug_attached():
    for module in sys.modules.values():
        if module.__name__ == 'debugpy':
            print('Debugger is attached')
            return True

    print('Debugger is not attached')
    return False

if __name__ == '__main__':
    is_debug_attached = check_is_debug_attached()
    print(f'is_debug_attached: {is_debug_attached}')
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you
  • Low reputation (1):
Posted by: Herman Ho