Thursday, January 30, 2025

Breakpoint conditions and ignore counts

 PyScripter has always supported conditional breakpoints.   Conditional breakpoints allow you to finetune the debugging experience, by only stopping execution when certain conditions are met.

Consider the following example:

def main():
    sum = 0
    for i in range(1000):
        sum = sum + i
    print(sum)

if __name__ == '__main__':
    main()

Say you are interested to know when sum becomes >= 1000.  If you set a breakpoint at the 4th line of the code, it will be tedious and time consuming to reach that point.   What you can do is to set a conditional breakpoint:


When you debug the code, execution will stop at the break point only when the condition is met (i = 46).

As you can tell from the screenshot above, the forthcoming version of PyScripter, introduces and new breakpoint property "Ignore Count".  If you set the the Ignore Count to a positive integer value, then the breakpoint will be ignored a number of times equal to that value.  So in the above example if you remove the condition and set the Ignore Count to 100, execution will stop when i becomes 100.  When you resume execution, the breakpoint will be ignored another 100 times.

There are a few ways to set the breakpoint properties Condition and Ignore Count.

  • In the Breakpoints Window select the property you want to change and press F2.  This will allow you to edit the property directly.  Press Enter when you are done:


  • In the Breakpoints Window right-click on the breakpoint and select "Breakpoint Properties...".  A dialog box like the following pops up and you can edit the values.



  • In the editor, when you click on a breakpoint you get a context menu (new feature) from which you can select "Breakpoint Properties..."


Another breakpoint tip:

  • You can quickly disable/enable a breakpoint by Ctrl + clicking on it in the editor gutter.


No comments: