Debugging the Program
In this step we'll add breakpoints to the program and "debug" it. That is, we'll run the
program in chunks, so that we can watch variables and view output as it is generated.
- Set a breakpoint On the "xmlrpcdemo.py" tab, click on the grey margin to the left of 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
buttons). In the
Debugging Options dialog,
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 Variables tab. If necessary,
resize the pane by
clicking and dragging the upper margin. On
the Locals tab, we see 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 Into Select
Debug|Step Into .
"Step Into" is a debugger command that causes the debugger to execute the current line and then
stop at the next processing line (line 12).
- Step Into again When line 12 is processed, if a match is found, the debugger
will step to line 13. Otherwise, it will return to line 9 and process the next category.
- 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 to the left of 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 Output tab. Notice that the HTML contained in the
"Print" statement on line 23 has been written to the Output window.
- Set another breakpoint Click on the grey margin to the left of 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 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. |
|