Search code examples
python-2.7debuggingcommand-linepdb

Is it possible to ignore a hardcoded pdb breakpoint?


I use pdb to debug a Python 2.7 script that includes hardcoded breakpoints using the pdb.set_trace() function. When I want to run the script without stopping at the breakpoints I have to comment out all the pdg.set_trace() lines, and then when I want to stop at the breakpoints I have to remove the comments which is very inefficient. Is there a way (e.g. a command-line flag) to execute a python script ignoring all the hardcoded breakpoints. For instance, many IDEs like PyCharm have Run Mode which ignores the breakpoints, and Debug Mode which stops at the breakpoints. Can I do something like that from the command line?


Solution

  • No, this is not a feature in pdb. However you can write the command line option handling into your program and set a global variable such as DEBUG_MODE = True then you just modify all your pdb.set_trace() calls to be:

    if DEBUG_MODE:
        pdb.set_trace()