[Twisted-Python] finer control of deferToThread ?

Josef Novak josef.robert.novak at gmail.com
Sat Dec 15 00:10:53 EST 2007

  I am writing a twisted application using StarPY fastagi API for
Asterisk.  My application involves answering user calls, and then
based on their responses to an IVR dialogue, running some some
compute-intensive applications on the same server, after they hang up.
  At the moment I am running the compute-intensive application (3rd
party code) in a deferred.deferToThread.  The application works fine,
however if the number of callers goes above 2-3, and one of the
compute-intensive applications from a previous call has not finished
up, the audio for the call gets very jumpy because of CPU usage.
  This compute-intensive process needs to be run immediately after
hangup, and I'd prefer to take care of everything on the same machine
(rather than send the compute-intensive application request somewhere

  What I'd like to do is pause the thread with the
deferred.deferToThread process any time a new  call comes in (this
sort of violates what I'm saying above but the number of calls going
to a particular ASterisk trunk is limited so in most cases this would
never result in more than a couple-seconds delay, which is

  Is there any way to control these deferred.deferToThread objects in
a more fine-grained manner?  Say from a reactor factory?  Can I
register them separately somehow, and then pause these
compute-intensive applications temporarily every time a new call comes
in?  I'm imagining something as simple as as ctrl+z and $ fg linux
terminal commands... but I appreciate that it is probably not so


More information about the Twisted-Python mailing list