[Grok-dev] Graphical debugging of Grok with Komodo IDE

Sebastian Ware sebastian at urbantalk.se
Fri Aug 31 08:32:21 EDT 2007


I just want to post a howto on how to setup the Komodo IDE graphical  
debugger for your Grok project.


   a) either in the terminal before you execute the "bin/zopectl fg"  

   b) or (if you start Zope from Komodo) by adding PYTHONPATH with a  
path to the
      Komodo debugger library. Go to "Preferences / Environment /  
New..." and
      add Name= PYTHONPATH, Value= /path/to/debugger_library

      The Komodo Python debugger library is called "dbgp". In Macosx  
you can find it
      the Komodo IDE.app package under Contents/SharedSupport/. I  
actually copied it
      to another location but I don't think that is necessary.

2 Make sure that the Komodo debugger listens to the right port

    Go to "Preferences / Debugger / Connection" and choose "a  
specific port". I selected
    port 9000 (but I think anything above 1024 should be ok in Macosx).

3 Add the following two lines anywhere in a .py file in your project  
(outside any class or method definition)

    import dbgp.client
    dbgp.client.brk(host="localhost", port=9000)

    Note that it supports remote debugging, but that requires you  
opening the firewall on the
    computer running the debugger.

4 Start Zope from within Komodo IDE

    I use the following macro (search for "macro" in Komodo help to  
learn how to
    create a macro) and have a keybinding to "shift-command r":

    // Macro recorded on Tue Jun 19 2007 21:08:09 GMT+0200 (CEST)
    if (komodo.view) { komodo.view.setFocus() };
    setTimeout(function(ko, win) {
               ko.run.runEncodedCommand(win, '/your/path/to/bin/ 
zopectl fg');
               }, 200, ko, window);

    // Note "200" is the delay before starting the server, allowing  
the output.kill command to
    // execute properly. You might want to extend this on a slower  

Zope will start and stop at the "clien.brk" command added in step 3.  
You can add and remove your break points and press the "Go / continue  
debugging" button in the toolbar. The Komodo debugger supports  
regular, conditional, variable based, function call, function return  
and exception base breakpoints.  (At the time of writing I have only  
set regular line based breakpoints.)

Once the Komodo debugger breaks at a break point you can:

-step into/over/return from statements
-inspect local/global/watch variables
-check the call stack
-enter interactive mode to perform arbitrary python code (this gives  
you a Python prompt, not the pdb prompt)

Mvh Sebastian

More information about the Grok-dev mailing list