You are not logged in Log in Join
You are here: Home » Members » mcdonc » HowTos » Using The Zope Debugger

Log in
Name

Password

 

Using The Zope Debugger

(created from Jim Fulton's presentation given at the 9th International Python Conference).

The Debugger is your Friend

Sets up a request environment

Simple tests

Debugging

Timing

Profiling

Simple testing

You can do simple tests:

     cd lib/python

     python

     import Zope

     Zope.debug('/manage_addFolder?id=foo', u='jim:123') 

You can use this mode with external debuggers like Wing and Komodo.

Debugging with pdb

Same as before, but add the d argument:

     python

     import Zope

     Zope.debug('/manage_addFolder?id=foo', u='jim:123', d=1) 

Breakpoints are preset to allow you to continue to predefined points of interest.

Entry to publishing (just above) entry to application code

Post-mortem debugging

Use the pm option:

     import Zope

     Zope.debug('/manage_addFolder?id=foo', u='jim:123', pm=1) 

If there's an error, use pdb.pm:

     import pdb

     pdb.pm() 

Time execution

Use t option:

     python

     import Zope

     Zope.debug('/manage_main, u='jim:123', t=1) 

Executes once, to warm up, and then runs 100 times, computing average time.

Includes publisher overhead.

Can modify repeat count lamely:

     import ZPublihser.Test

     ZPublisher.Test.repeat_count=10 

Using the Python profiler

Supply the name of a statistics file via the p option:

     import Zope

     Zope.debug('/manage_addFolder?id=foo',u='jim:123', p='prof.dat')

     import pstats

     s=pstats.Stats('prof.dat')

     s.print_stats() 

Setting request variables

You can provide extra request variables via the extra argument:

     Zope.debug('/manage_addFile?id=foo', u='jim:123',d=1, extra={'file': open('test.dat')} )

The .bobodb file

Read when the d option is used.

Used to set breakpoints or set up "environment" data:

     import OFS.Folder
     breakpoints=(OFS.Folder.manage_addFolder, ) env={'rows': '20'}