From 903843730a9916105352c729e94136a755b5e529 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 4 Jun 2022 22:33:12 -0700 Subject: [PATCH] Detect a debugger. --- misc_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/misc_utils.py b/misc_utils.py index f844f72..669b3ef 100644 --- a/misc_utils.py +++ b/misc_utils.py @@ -5,6 +5,7 @@ """Miscellaneous utilities.""" import os +import sys def is_running_as_root() -> bool: @@ -16,6 +17,13 @@ def is_running_as_root() -> bool: return os.geteuid() == 0 +def debugger_is_attached() -> bool: + """Return if the debugger is attached""" + + gettrace = getattr(sys, 'gettrace', lambda: None) + return gettrace() is not None + + if __name__ == '__main__': import doctest -- 2.47.1