Personal tools
You are here: Home Documentation How-Tos Graphical debugging of Grok with Komodo IDE

Graphical debugging of Grok with Komodo IDE

This How-to applies to: Any version.
This How-to is intended for: Developer

Set up the Komodo IDE graphical debugger for your Grok project.

1 Set the PYTHONPATH

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

    http://community.activestate.com/forum-topic/debugging-zope-apps

 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 have a python virtualenv installation)

  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)

  var appname = 'YHGuiden';

  var sandbox = '/path/to/my/projects';

  var pythonCmd = sandbox + '/bin/python';

  var startCmd = sandbox + '/' + appname + '/parts/app/runzope -C ' + sandbox + '/' + appname + '/parts/zopectl/zope.conf';

  komodo.assertMacroVersion(2);

  ko.run.output.kill(-1);

  if (komodo.view) { komodo.view.setFocus() };

  setTimeout(function(ko, win) {

      ko.run.runEncodedCommand(win,  pythonCmd + ' ' + startCmd);

  }, 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 computer.

   

To run zope, use the runzope command, otherwise, when you kill the process in order to restart, it won't kill the server process, only the zopectl process. In a terminal window (unix), if you have started your Grok app with the zopectl command, you can use... 

   ps -aux | grep python

...to find the path and parameters to sen to runzope.

 

Zope will start and stop at the "client.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)

see also:

Using Virtualenv for a clean Grok installation
NOTE: As of Grok 1.2, you do not need to use virtualenv. Grok is automatically isolated from the system python environment.