Pydev as debugging technique

Skip to first unread message


Dec 11, 2010, 2:55:40 AM12/11/10
to modwsgi
There is no mention of Eclipse plug-in Pydev in the Debugging
Techniques Wiki page. Pydev debugger works pretty well, even on
multiple httpd processes, and clearly it looks somewhat more user
friendly than PDB.
If you accept contributions, I can provide a small paragraph on that

Graham Dumpleton

Dec 11, 2010, 3:30:02 AM12/11/10

Start out by posting any information here and we see how it goes from there.

My time has been quite constrained last couple of years so have never
had time to get around to trying to get any of the IDE debugger tools
working, eg. WingIDE, PyDev etc, but is something I have wanted to do.

I have changed jobs now and new job may give me a lot more flexibility
as far as managing my time, but still got to see how things go.

I am also starting to think about what my PyCon conference
talk/tutorials might be about for 2011. PyCon in Singapore has just
called for papers and that would be first target, followed by Sydney
and New Zealand.

One of the thoughts for a talk and/or tutorial this year was to cover
debugging of Python web applications. There is some stuff on the wiki,
but obviously a lot more that isn't, including IDE debuggers. My new
job also relates to Python web application monitoring and debugging so
is a good tie in there as well.

So, may be timely that you are bringing this up.

I'll post separately about getting feedback on talk/tutorial topics
for next years conferences.



Dec 13, 2010, 4:25:35 AM12/13/10
to modwsgi
Great !

some instructions following. This assumes you already have a good
grasp of Eclipse and have already used the Eclipse debugging interface
before. There is nothing that much specific to modwsgi following
actually, so I will be more or less paraphrasing what is written in

In order to debug your application running with modwsgi you need
- Eclipse with Pydev (like Aptana from
- your application already configured to run with modwsgi
- read first

1- debugging a singlethreaded application (single or multiple
processes) on the server that runs Apache
2- debugging a multithreaded application
3- debugging from another host

1) debugging a singlethreaded application (single or multiple
processes) on the server that runs Apache
- in your Apache config, your WSGIDaemonProcess should be
configured with threads=1
- add this at the top of your .wsgi file:
import sys
org.python.pydev.debug_1.6.../pysrc' )
import pydevd
- in the Eclipse Debug perspective, start the pydev server
- run Apache and access your application
You should already be able to fully use the Debugger from here. Since
the debugger will suspend the program each time the settrace function
is called, quickly it will be cumbersome to manually resume it for
each process launched (especially if you're running like 20
processes), so if the above instructions worked so far, you can safely
replace the settrace call with:

2) debugging a multithreaded application:
The following instructions are not complete, and I'm not fully happy
with debugging multithreaded-application with this technique, but it
does work if you absolutely need it (I would recommend to stick to the
single thread-multi process though) ... let's get started
- you need to have the settrace function called in each separate
thread of the same application, but
- do to badly synchronized code as reported here
, we're going to call it one more time in the main thread. Your .wsgi
file will look like this:
( for example here for a Django app)
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
return _application(environ, start_response)
Here we ensure that the settrace is called for each threads, but from
my current experience it does not work that well (accessing the
application multiple times, it take several minutes to get it to
suspend 2 different threads). Maybe it will work ok for you though
- an alternative is to stick with the approach from 1) and set a
low number of threads. You will be able to put breakpoints only on the
main thread, but that should be enough to reproduce a race condition
for example.

3) debugging from another host
Assuming your apache server is running on a different box that the one
you usually use to run Eclipse, what you need to do is:
- ensure you can access the .wsgi and your application source code
from both hosts (from a network drive for example)
- copy the /path/to/eclipse/plugins/org.python.pydev.debug_1.6.../
pysrc to the box running Apache if it is not shared between the 2
- edit the file and locate the
PATHS_FROM_ECLIPSE_TO_PYTHON variable. Set it to something like this:
- above we're launching Eclipse from Windows, the source code of
the application and the wsgi are available under /remote/pathto/
yourhome/ on the Linux box running the Apache server, and those same
sources are mounted through a samba drive on the Z: network drive
under Windows (do not forget the \\ in the expression)

Your thoughts ?
Reply all
Reply to author
0 new messages