[mod_python] Using Twisted inside mod_python

Graham Dumpleton grahamd at dscpl.com.au
Thu May 5 23:53:53 EDT 2005

Damjan wrote ..
> > I have it running from a PythonImport and attaching to an interpreter
> and 
> > all that goodness.
> > It prints out all the queries and answers it received to the apache log
> just 
> > fine. Apache works just fine serving normal stuff.
> > 
> > The problem is anytime I make any kind of method calls into my global
> object 
> > from a handler it just hangs Apache2 :-(
> I have no idea what your code does, but one thing I thought maybe
> happens is this:
> http://spyced.blogspot.com/2005/04/how-well-do-you-know-python-part-5.html

Based on previous post, it isn't at least hanging in the PythonImport and
thus for that case, the referenced material wouldn't be relevant. The
original handler posted previously was:

  from mod_python import apache

  from myapp import cac
  from twisted.names import dns

  def handler(req):
    req.content_type = "text/plain"
    for answer in cac.getCachedResults(None, None, None):
      return apache.OK

If I understood where things were at, it was hanging somewhere inside
of call to cac.getCachedResults().

Question to the original poster. Have you added sufficient debug into each
step of the internals of that call so as to know precisely when the code
seems to block?

Also, does "cac" consist of simple Python data structures without locking,
or does it contain thread locks in anyway? Does it actually call into Twisted
in some way? Do you know that a separate thread can't call into Twisted
unless it uses appropriate mechanisms?

It is going to be really hard for us to say what is wrong unless you can
narrow it down to exactly where it may be blocking and provide relevant
code for it.


More information about the Mod_python mailing list