Is there a simple way to detect, within Python code, that this code is being executed through the Python debugger?
I have a small Python application that uses Java c
A solution working with Python 2.4 (it should work with any version superior to 2.1) and Pydev:
import inspect
def isdebugging():
for frame in inspect.stack():
if frame[1].endswith("pydevd.py"):
return True
return False
The same should work with pdb by simply replacing pydevd.py
with pdb.py
. As do3cc suggested, it tries to find the debugger within the stack of the caller.
Useful links: