Debugging Plone with Eclipse and PyDev remote debugger

Plone is a very heavy Python CMS containing thousands of modules. PyDev is Python extension for Eclipse IDE. Plone doesn’t run very well in PyDev debug mode:

  • Debug mode is many times slower than normal Python execution
  • At least on  some Linux system OS limitations prevent proper running [1]

But you can still use Eclipse and PyDev remote debugger to debug your software.

  • All communications happen over sockets so you can debug software running on test server besides local machine
  • Downsite is that you need to manually place pydevd.settrace() call to your code instead of just right clicking the line and choosing Set Breakpoint from menu

pydev_and_plone In both cases you need to use a custom non-forking Plone launch script from Plone and Eclipse tutorial which prevents Zope to escape itself into a child process and keeps the debug process information intact.

1. PyDev Extension remote debugger

Note that you need the commercial PyDev Extension license, this does not work with the basic plug-in. Free evaluation trial available. Get it here.

Benefits

  • GUI stepping support
  • Inspect Python run-time environment and variables using GUI
  • Better integration with Eclipse console

2. Setting up local remote debugger

0. Install Eclipse. Do a local install, do not trust your Linux distribution package installation. http://johnpaulett.com/2009/06/26/install-eclipse-galileo-3-5-on-ubuntu-jaunty-9-04/

1. Set up idelauncher.py for your Zope application server

2. Right-click your project in Eclipse. Put pydevd in your PyDev – PYTHONPATH -> External libraries. Mine (local Eclipse 3.5 install) is /home/moo/eclipse3.5/plugins/org.pyhon.pydev.debug.XXX/pysrc

3. Switch to Eclipse Debug perspective. Start pydevd server by clicking the icon with a bug and P letter.

3. Start your Plone instance / unit tests idelauncher.py using Run (play icon – not debug). The debug server stays active even if you terminate the application launcher run.

4. When your code runs to *import pydevd ; pydevd.settrace()* (no underscore in settrace()) you should be able to start examining your site in the debugger

Now you can

  • Examine and edit local variables in Variables view
  • Execute Python console commands
  • Examine different threads (kind of pointless with Plone…)

Note: Python console behaves funnily. You need to enter the commands to Console -> Display selected console (computer icon) -> Debug server view and output will appear  Console -> Display selected console (computer icon) -> your launcher name view.

3. Remote debugging not enabled

The following exception means that your pydevd server is not running. Click the P bug icon before running the launcher.

Traceback (most recent call last):
  File "/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd.py", line 624, in trace_dispatch
    return dbFrame.trace_dispatch(frame, event, arg)
  File "/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd_frame.py", line 107, in trace_dispatch
    raise
  File "/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd_frame.py", line 102, in trace_dispatch
    self.doWaitSuspend(thread, frame, event, arg)
  File "/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd_frame.py", line 25, in doWaitSuspend
    self._args[0].doWaitSuspend(*args, **kwargs)
  File "/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd.py", line 532, in doWaitSuspend
    def doWaitSuspend(self, thread, frame, event, arg): #@UnusedVariable
  File "/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd.py", line 539, in doWaitSuspend
    self.writer.addCommand(cmd)

4. Pydevd and Linux Resource temporarily unavailable

[1] I get the following Resource temporarily unavailable traceback when I try to run PyDev debugger against Plone – I tried to pindown the reason using strace, but no luck. Applies both for unit testing and for the actual instance launch.

Installing PloneLanguageTool ... done (0.174s)
Running Products.SitsHospital.tests.rememberbase.RememberProfileLayer tests:
  Set up Products.PloneTestCase.layer.ZCML
Traceback (most recent call last):
...
  File "/home/moo/sits/parts/zope2/lib/python/zope/testing/testrunner.py", line 688, in setup_layer
    setup_layer(base, setup_layers)
  File "/home/moo/sits/parts/zope2/lib/python/zope/testing/testrunner.py", line 692, in setup_layer
    layer.setUp()
  File "/home/moo/sits/parts/plone/PloneTestCase/layer.py", line 17, in setUp
...
  File "/usr/lib/python2.4/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.4/xml/sax/expatreader.py", line 207, in feed
    self._parser.Parse(data, isFinal)
  File "/usr/lib/python2.4/xml/sax/expatreader.py", line 348, in end_element_ns
    self._cont_handler.endElementNS(pair, None)
  File "/home/moo/sits/parts/zope2/lib/python/zope/configuration/xmlconfig.py", line 349, in endElementNS
    self.context.end()
  File "/home/moo/sits/parts/zope2/lib/python/zope/configuration/config.py", line 544, in end
    self.stack.pop().finish()
  File "/home/moo/sits/parts/zope2/lib/python/zope/configuration/config.py", line 692, in finish
    actions = self.handler(context, **args)
  File "/home/moo/sits/parts/plone/PlacelessTranslationService/patches.py", line 27, in compile_translations
    func(*args, **kwargs)
  File "/home/moo/sits/eggs/zope.i18n-3.7.0-py2.4.egg/zope/i18n/zcml.py", line 57, in registerTranslations
    for language in os.listdir(path):
zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/home/moo/sits/parts/instance/etc/site.zcml", line 5.2-5.37
    ZopeXMLConfigurationError: File "/home/moo/sits/parts/zope2/lib/python/Products/Five/configure.zcml", line 6.2-6.30
    ZopeXMLConfigurationError: File "/home/moo/sits/parts/zope2/lib/python/Products/Five/i18n.zcml", line 24.4-24.52
    OSError: [Errno 11] Resource temporarily unavailable: '/home/moo/sits/parts/zope2/lib/python/zope/app/locales'
Debugging Plone with PyDev Extensions remote debugger

Plone is a very heavy Python CMS containing thousands of modules. Plone doesn’t run very well in PyDev debug mode (normal process launch):

* Debug mode is many times slower than normal execution

* At least on Linux some system limitations prevent proper running [1]

You can still use PyDev remote debugger to debug your software http://fabioz.com/pydev/manual_adv_remote_debugger.html

* All communications happen over sockets so you can debug software running on test server besides local machine

* Downsite is that you need to manually place pydevd.settrace() call to your code instead of just right clicking the line and choosing Set Breakpoint from menu

In both cases you need to use a custom non-forking launch script which prevents Zope to escape itself into a child process and keeps the debug process information intact.

PyDev Extension remote debugger

Note that you need the commercial PyDev Extension license, this does not work with the basic plug-in. Free evaluation trial available. Get it here. http://fabioz.com/pydev/download.html

Benefits

– GUI stepping support

– Inspect Python run-time environment and variables using GUI

– Better integration with Eclipse console

Setting up local remote debugger

0. Install Eclipse. Do a local install, do not trust your Linux distribution package installation. http://johnpaulett.com/2009/06/26/install-eclipse-galileo-3-5-on-ubuntu-jaunty-9-04/

1. Set up idelauncher.py for your Zope application server

2. Right-click your project in Eclipse. Put pydevd in your PyDev – PYTHONPATH -> External libraries. Mine (local Eclipse 3.5 install) is /home/moo/eclipse3.5/plugins/org.pyhon.pydev.debug.XXX/pysrc

3. Switch to Eclipse Debug perspective. Start pydevd server by clicking the icon with a bug and P letter.

3. Start your Plone instance / unit tests idelauncher.py using Run (play icon – not debug). The debug server stays active even if you terminate the application launcher run.

4. When your code runs to *import pydevd ; pydevd.settrace()* (no underscore in settrace()) you should be able to start examining your site in the debugger

Now you can

– Examine and edit local variables in Variables view

– Examine different threads (kind of pointless with Plone…)

– Execute Python console commands

Note: Python console behaves funnily. You need to enter the commands to Console -> Display selected console (computer icon) -> Debug server view and output will appear  Console -> Display selected console (computer icon) -> your launcher name view.

Remote debugging not enabled

The following exception means that your pydevd server is not running. Click the P bug icon before running the launcher.

Traceback (most recent call last): File “/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd.py”, line 624, in trace_dispatch return dbFrame.trace_dispatch(frame, event, arg) File “/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd_frame.py”, line 107, in trace_dispatch raise File “/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd_frame.py”, line 102, in trace_dispatch self.doWaitSuspend(thread, frame, event, arg) File “/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd_frame.py”, line 25, in doWaitSuspend self._args[0].doWaitSuspend(*args, **kwargs) File “/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd.py”, line 532, in doWaitSuspend def doWaitSuspend(self, thread, frame, event, arg): #@UnusedVariable File “/home/moo/eclipse3.5/plugins/org.python.pydev.debug_1.4.7.2843/pysrc/pydevd.py”, line 539, in doWaitSuspend self.writer.addCommand(cmd)

[1] I get the following traceback when I try to run PyDev debugger against Plone – I tried to pindown the reason using strace, but no luck:

Installing PloneLanguageTool … done (0.174s) Running Products.SitsHospital.tests.rememberbase.RememberProfileLayer tests: Set up Products.PloneTestCase.layer.ZCML Traceback (most recent call last): … File “/home/moo/sits/parts/zope2/lib/python/zope/testing/testrunner.py”, line 688, in setup_layer setup_layer(base, setup_layers) File “/home/moo/sits/parts/zope2/lib/python/zope/testing/testrunner.py”, line 692, in setup_layer layer.setUp() File “/home/moo/sits/parts/plone/PloneTestCase/layer.py”, line 17, in setUp … File “/usr/lib/python2.4/xml/sax/xmlreader.py”, line 123, in parse self.feed(buffer) File “/usr/lib/python2.4/xml/sax/expatreader.py”, line 207, in feed self._parser.Parse(data, isFinal) File “/usr/lib/python2.4/xml/sax/expatreader.py”, line 348, in end_element_ns self._cont_handler.endElementNS(pair, None) File “/home/moo/sits/parts/zope2/lib/python/zope/configuration/xmlconfig.py”, line 349, in endElementNS self.context.end() File “/home/moo/sits/parts/zope2/lib/python/zope/configuration/config.py”, line 544, in end self.stack.pop().finish() File “/home/moo/sits/parts/zope2/lib/python/zope/configuration/config.py”, line 692, in finish actions = self.handler(context, **args) File “/home/moo/sits/parts/plone/PlacelessTranslationService/patches.py”, line 27, in compile_translations func(*args, **kwargs) File “/home/moo/sits/eggs/zope.i18n-3.7.0-py2.4.egg/zope/i18n/zcml.py”, line 57, in registerTranslations for language in os.listdir(path): zope.configuration.xmlconfig.ZopeXMLConfigurationError: File “/home/moo/sits/parts/instance/etc/site.zcml”, line 5.2-5.37 ZopeXMLConfigurationError: File “/home/moo/sits/parts/zope2/lib/python/Products/Five/configure.zcml”, line 6.2-6.30 ZopeXMLConfigurationError: File “/home/moo/sits/parts/zope2/lib/python/Products/Five/i18n.zcml”, line 24.4-24.52 OSError: [Errno 11] Resource temporarily unavailable: ‘/home/moo/sits/parts/zope2/lib/python/zope/app/locales’

One thought on “Debugging Plone with Eclipse and PyDev remote debugger

  1. Thank you for this nice tutorial.

    A word about “Pydevd and Linux Resource temporarily unavailable”

    It is a bug fixed in python2.6: http://bugs.python.org/issue3494

    It would be nice to distribute a patch that fix this in the old python 2.4. Or at least you can use Plone 4.

Leave a Reply

Your email address will not be published. Required fields are marked *