Configure Python exceptions

To investigate Python exceptions without setting breakpoints by hand, configure actions for the following debugger-defined pseudo-signals. These pseudo-signals act independently, so changing the action for one does not affect the others.

  • Stop on Raised Python Exception

    The pseudo-signal PYTHON_EXC_RAISED represents any Python exception being raised, whether or not a handler later catches it. Its default action is Ignore.

  • Stop on Uncaught Python Exception

    The pseudo-signal PYTHON_EXC_UNCAUGHT represents an exception that no handler catches anywhere on the call stack, so it would otherwise end the program with a traceback. A caught exception does not trigger this signal, even when Stop on Raised Python Exception (PYTHON_EXC_RAISED) is set to Ignore. The debugger breaks at the original raise site, before the interpreter unwinds the stack or prints the traceback. Its default action is Stop.

  • Stop on User-Uncaught Python Exception

    The pseudo-signal PYTHON_EXC_USER_UNCAUGHT represents an exception raised in your code that is not caught before it propagates into a library or third-party function. If your code does not call library code at that point, this signal behaves like Stop on Uncaught Python Exception (PYTHON_EXC_UNCAUGHT). Its default action is Ignore.

For these pseudo-signals, the Error and Stop actions stop execution. The Resend and Ignore actions do not stop execution. Because these pseudo-signals do not correspond to operating-system signals, there is no signal for TotalView to resend. With Ignore, Python handles the exception as it would without TotalView.

Set a Python exception signal action using the Preferences dialog

Use the following procedure to set a Python exception signal action in the Preferences dialog: 

  1. Select File > Preferences.

  2. In the Preferences dialog, select SIGNALS.

  3. In the signals table, locate the Python exception signal you want to configure:

    • Stop on Raised Python Exception (PYTHON_EXC_RAISED)

    • Stop on Uncaught Python Exception (PYTHON_EXC_UNCAUGHT)

    • Stop on User-Uncaught Python Exception (PYTHON_EXC_USER_UNCAUGHT)

  4. In the Action column, select the action to take when the exception occurs: Error, Stop, Resend, or Ignore.

For more information, see Signal Action Settings.

Set a Python exception signal action using the command line

Use the TV::signal_handling_mode state variable to set a Python exception signal action.

The following commands demonstrate how to set the Stop action on the corresponding exception event:

  • Stop whenever an exception is raised:

    dset TV::signal_handling_mode {stop=PYTHON_EXC_RAISED}

  • Stop only when an exception is uncaught:

    dset TV::signal_handling_mode {stop=PYTHON_EXC_UNCAUGHT}

  • Stop when an exception from your code propagates into library or third-party code:

    dset TV::signal_handling_mode {stop=PYTHON_EXC_USER_UNCAUGHT}