debug CGI with complex forms

R. Bernstein rocky at panix.com
Sat Apr 8 12:22:33 EDT 2006


"Sullivan WxPyQtKinter" <sullivanz.pku at gmail.com> writes:

> When the form in one HTML is very complex with a lot of fields(input,
> button,radio,checkbox etc.), setting the environment is quite
> burdernsome, so I usually change the stdout and stderr of the submit
> processing script to a file object to see the output directly from that
> file. This just can do, but still inconvinient.
> Anyone has more suggestions?

The extended Python debugger (http://bashdb.sourceforge.net/pydb) has
the ability to give POSIX-style line tracing, and to change the debugger
stdout/stderr to a file you direct it. For example,
   pydb --trace --output=/tmp/dbg.log --error=/tmp/error.log my-cgi

Rather than trace the entire CGI, if there is a specific portion that
you want traced that can be done too by changing the CGI. Create a
files called "/tmp/trace-on" and "/tm/trace-off". "/tmp/trace-on" might
contain this:

  # Issue debugger commands to set debugger output to 
  # go to a file, turn on line tracing, and continue
  set logging file /tmp/dbg.log
  # uncomment the following line if you want to wipe out old dbg.log
  # set logging overwrite on
  set logging redirect on
  set logging on
  set linetrace on
  continue

and /tmp/trace-off:

  # Issue debugger commands to turn off line tracing and continue
  set linetrace off
  continue

In your CGI (in the above command-line example the CGI was called
"my-cgi") add:

   import pydb   # needs to be done only once
   ...
   pydb.set_trace("/tmp/trace-on")
   # This and subsequent lines will be traced
   ...
   pydb.set_trace("/tmp/trace-off")

Of course modify the file names in the examples above, my-cgi,
/tmp/dbg.log /tmp/trace-on, /tmp/trace-off as appropriate.

I notice that line tracing at present doesn't show the text of traced
lines just the position (file name, line number, and possibly
function/method name). I will probably change this pretty soon in CVS
though.

Finally, I don't know if any of this will help, but I guess if it
doesn't it would be interesting to understand how it fails. 

(If my past experience in c.l.p holds here, if nothing else, my having
posted this will at least motivate someone else to give other
method(s). ;-)







More information about the Python-list mailing list