Debugging the Program
In this step you will add breakpoints to the program and "debug" it. Adding
breakpoints lets you run the program in chunks, making it easier to watch variables
and view output as it is generated.
- Set a breakpoint On the "xmlrpcdemo.py" tab, click on the grey margin immediately
to the left of the code on line 9 of the program. This will set a breakpoint, indicated by a green circle.
- Run the debugger Select Debug|Start (or <F5>, or use the Debug Toolbar). In the Debugging Options
dialog box, click OK to accept the defaults.
Komodo Tip Debugger commands can be accessed
from the Debug menu, by shortcut keys, or from the Debug Toolbar. For a summary of debugger
commands, see Debugger
Command List |
- Watch the debug process Notice that the breakpoint turns red, which indicates that the
debugger is running. A yellow arrow on the breakpoint indicates the position at which the debugger has halted.
- View variables On the
Output Pane,
click the Debug Variables tab. If necessary,
resize the pane by
clicking and dragging the upper margin. On
the Locals tab, notice that the declared variables have been assigned values. Click on the "+" symbol to
the left of the "categories" variable to view all the items in the list.
Komodo Tip "Why are there only 10 items in the "categories" variable?
There are more than 10 categories on the Meerkat site." Tracking a large number of variable values slows down the
debugger. In circumstances where you specifically want to view more than ten items, use the
Watched Variables
pane. For example, in this case, you could enter "categories[10:20]" in the Variable Name field of the
Watched Variables pane to view more items in the "categories" variable. |
- Step In Select Debug|Step In until the debugger stops
at line 12. "Step In" is a debugger command that causes the debugger to execute the current line and then
stop at the next processing line.
- Step In again When line 12 is processed, if a match is found, the debugger
will step into line 13. Otherwise, it will return to line 9 and process the next category.
- Step Out Select Debug|Step Out. On the Locals tab, notice that the value
of the "category" variable has changed. If a match is found, the "interestingCategories" variable will display a
value.
Komodo Tip What do the debugger commands
do?
- Step In executes the current line of code and pauses at the following line.
- Step Over executes the current line of code. If the line of code calls a
function or method, the function or method is executed in the background and the debugger
pauses at the line that follows the original line.
- Step Out when the debugger is within a function or method, Step Out will execute
the code without stepping through the code line by line. The debugger will stop on the line of
code following the function or method call in the calling program.
|
- Remove a breakpoint Click on the red breakpoint at line 9. This removes
the breakpoint, but does not stop the debugger.
- Set another breakpoint Click on the grey margin immediately to the left of
the code in line 21 to set another breakpoint.
- Step Out Because the breakpoint on line 9 has been removed, Step Out now
runs through the entire routine on lines 9 to 13 without stopping, and continues until it encounters the
next breakpoint on line 21.
- View output Click on the Debug Output tab. Notice that the HTML contained in the
"Print" statement on line 16 has been written to the Output Pane.
- Set another breakpoint Click on the grey margin immediately to the left of
the code on line 29 to set another breakpoint.
- Step Out Select Step Out to process the code on lines 21 to 27. On the Variables
tab, notice that the "params" variable has two components: the ID number of the current category,
and the maximum article age.
- View Output Click the Debug Output tab. Click Step Out repeatedly, and watch as each
article that falls within the "params" criteria is formatted in HTML tags.
- Continue To run the program to the end, remove the breakpoints and
select Debug|Continue.
Python Pointer "Why are there no articles in the output?"
If no article references are created in the Output Pane, no articles have been picked up by Meerkat in
the period specified in the "time_period" criterion on line 26. Try increasing the number of hours. |
|