[mod_python] Using Twisted inside mod_python

Graham Dumpleton grahamd at dscpl.com.au
Fri May 6 01:59:01 EDT 2005

jarrod roberson wrote ..
> On 5/5/05, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
> > 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?
> that call basically walks a list filters out some items and builds another
> list to return
> I have done alot of basic debugging and the problem is it just hangs apache
> and I have to kill it.
> Thus it doesn't print anything out because it doesn't shut down correctly.

Is your debug using "print" or "apache.log_error()" from mod_python. If the
latter, it should be logged to Apache log straight away and adding sufficient
debugging should be able to identify place it stops if it reliably stops in the
same place. Is there any evidence it stops at the same place? Does Apache
process go to idle, or does it look to be stuck in a tight loop and hogging
all the CPU? Depending on what platform you are using, does use of ktrace,
ptrace, strace or truss, indicate that Apache process is stuck within certain
system calls? These tools should be able to pointed at the process using its
pid. Tools on Mac OS X are good for this sort of debugging as can show where
different threads are and whether they are waiting on locks etc.

> Do you know that a separate thread can't call into Twisted
> > unless it uses appropriate mechanisms?
> I do now, what I don't know is what "appropriate mechanisms" is specifically

I don't use Twisted, but based on recent comp.lang.python post, there is a
call "callFromThread". Example on the new group was:

  import time 
  from twisted.internet import reactor 

  def shutdown(): 

      print "stopping" 
      reactor.callFromThread(reactor .stop) 


Don't know much more than that.


More information about the Mod_python mailing list