[Twisted-Python] Need advice on changing blocking calls to be Twisted-aware...

Stuart Hungerford stuart.hungerford at anu.edu.au
Tue May 20 02:07:43 EDT 2003


Hi all,

I'm running a web application which makes use of the excellent
Twisted.Web resource framework with customized .getChild() and
.render() calls.

In one of the resource .render() methods I've reached a point
where the method needs some information on from the system via
an os.popen2() call. This information is needed to be turned
into HTML, and the HTML generation can't proceed without it.

What I'm effectively doing in the render() call is:

         def render(...)
             ...generate some HTML
             do blocking system call
             ...generate some more HTML

Which I understand is a no-no in the reactor and callback
based Twisted framework. I believe that the Twisted way to do
this is with a reactor.spawnProcess() call which in turn
returns a Deferred object.  Or maybe I should be using
threads instead?

Can someone point me to some example code where a
blocking-system-call-and-it's-results-needed-here pattern
is expressed in the spawnProcess/Deferred/callback world
of Twisted?



Cheers,

Stu

--
:: Stuart Hungerford (stuart.hungerford at anu.edu.au)
:: ANU Internet Futures Group





More information about the Twisted-Python mailing list