()
return sys.gettrace() is not None
Attempts to detect if running under a debugger
Attempts to detect if running under a debugger
Attempts to detect if running under a debugger
def is_under_debugger() -> bool:
    """
    Attempts to detect if running under a debugger
    """
    frames = inspect.stack()
    if len(frames) >= 3:
        filename = frames[-3].filename
        if filename.endswith("/pdb.py"):
            return True
        elif filename.endswith("/pydevd.py"):
            return True

    # unknown debugging will sometimes set sys.trace
    return sys.gettrace() is not None
def is_under_debugger ( ) -> bool : frames = inspect . stack ( ) if len ( frames ) >= 3 : filename = frames [ - 3 ] . filename if filename . endswith ( "/pdb.py" ) : return True elif filename . endswith ( "/pydevd.py" ) : return True # unknown debugging will sometimes set sys.trace return sys . gettrace ( ) is not None