1. Debugging

Debugging Cantemo we have several helper functions, which are based on certain configuration options.

1.1. Settings

If the settings DEBUG and TEMPLATE_DEBUG is set to true, you will get exceptions and other messages formatted in HTML pages as they happen.

1.2. Logging

Firstly check the log files on DEBUG level. This will give an overview on how fast a process is responding, what low level functions are being called and any communication with plugins is happening. You can also see the time taken to respond to messages.

1.3. Profiling Middleware

The profiling middleware gives an overview of what is happening and which modules are taking up what time on the system.

It needs to be enabled by putting in ‘utils.middleware_profile.ProfileMiddleware’ into the middleware tuple. After that you can append ?lookie to the URL to see what module is taking up what time on a request.

1.4. IPDB

Sometimes, you may want to inspect your running code using a single-step debugger. The easiest way to do that is to install ipdb and set a breakpoint in your code.

Start by installing ipdb in your Cantemo environment:

# /opt/cantemo/python/bin/pip install ipdb

You can then add the following statement in the code where you want to break into the debugger:

import ipdb; ipdb.set_trace()

You must then start the Cantemo web worker in a terminal so you can control the debugger. First, stop the normal Cantemo worker:

systemctl stop portal-web.service

Then start Cantemo manually:

sudo -u www-data /opt/cantemo/portal/manage.py runserver 9000

After this, when you make a call to the code where you have set the breakpoint, you should see something similar to the following in your terminal:

[cantemo@portal ~]$ /opt/cantemo/portal/manage.py runserver 9000
Validating models...

0 errors found
Django version 1.4.22, using settings 'portal.settings'
Development server is running at http://127.0.0.1:9000/
Quit the server with CONTROL-C.
> /opt/cantemo/portal/portal/plugins/yourappname/views.py(28)__call__()
     27
---> 28         log.debug("%s Viewing page" % self.request.user)
     29         ctx = {}

ipdb>

You can now inspect the running code and step through your code.