[Stackless] Let's Make a Case Re: The case for Twisted

Andrew Francis andrewfr_ice at yahoo.com
Mon Aug 13 21:36:16 CEST 2007

Hello Christopher:

>Sorry for not acknowledging this immediately. 

No problem.

>I did know you did that,and I know it's possible
since >I wrote simple Deferred integration years ago,
as I >think you're aware :-)

1. Christopher, I think it is important to illustrate
how integration is done with examples, documentation,
and discussion. There are a shortage of
Stackless/Twisted examples. In contrast, I learnt much
from studying uThread.py and Richard Tew's MUD server.

2. I feel our approaches try to achieve different
things. As I explained before, I encountered
situations where I believe blockOn would fail. I am
not sure if these problems are because of bad design
on my part, or something endemic to the way Stackless
interoperates with Twisted. 

Nevertheless I have a solution although it has less to
be desired performance (I would appreciate feedback .
The solution allows me to do things like safely invoke
Twisted calls from a Request Handler.


class MyRequestHandler(http.Request):
    let us create a tasklet to do work in the request
    and allow the Reactor to continue
    def process(self):
        t = stackless.tasklet(self.doWork)()
    def doWork(self):    
        make a call to a web server from the Request
Handler. I have a layer between my application and
Twsited that handles deferreds.
        result =
        # echo result back to the HTTP client
class MyHttp(http.HTTPChannel):
    requestFactory = MyRequestHandler
The place where this is useful for the average
developer is communicating with a database or a web
service. I suspect writing the same code with Twisted
alone would be tricky. 

>A very high level API such as the one you've
described >is desirable (in fact, I would imagine your
Deferred >integration should pretty much already do
this, given >there's already a client.getPage which
>a Deferred).

Again Christopher, the technical demands of my WS-BPEL
processor dictates how I use Twisted and which issues
I pursue. However one of main things that I have done
is to hide the nitty-gritty of Deferreds. I believe
this approach can be generalised through use of, for
lack of a better term, a custom "reactor" (I know
Glyph's feelings on custom reactors) and import module
tricks (a la StacklessSocket). Right now, it is easy
for me to do this:

def execute(self):
            # hide simple deferreds from user
        except TwistedException:
            log.msg("A Twisted Exception was thrown")
        except  :
            log.msg( sys.exc_info() )

Give me a day or two, and I will post some examples.


Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list