[Twisted-Python] Wrapping a Perspective

Andrew Francis andrewfr_ice at yahoo.com
Fri Sep 7 13:16:12 EDT 2007


Hi Rasjid:

>I have read about Stackless, and it looks like it
>would be really fun to play with.  But I don't think
my employer would be keen to go as 'fringe' as
Stackless.

Once you get the swing of it, Stackless Python is
pretty fun... and powerful. Even more fun when one
figures out how to properly integrate Stackless Python
with Twisted. 

Anyhow I haven't played with the Perspective Broker
before. So I read the Bruce Eckel "Grokking Twisted"
article and wrote a simple example to illustrate how
to make Twisted inter-operate with Stackless. 

The essense of the solution is the approach Armstrong
takes in threadless.py.  I provide a bit more
syntactic sugaring: 

1) Use a proxy that slightly modifies the method
calls, mainly to hide the underlying deferred.

2) trigger a "TwistedException." 

example fragment:

   def execute(self, host, port):
        global flag
        
        factory = pb.PBClientFactory()
        log.msg("connecting")
        reactor.connectTCP(host, port, factory)
        log.msg("connected")
        
        try:
           perspective =
self.processor.getRootObject(factory)
           print "=>",
processor.calculate(perspective, 10, 20)
           flag = False
        
        except TwistedException:
            log.msg("A Twisted Exception was thrown")
            log.msg(sys.exc_info())

One of my long term goals is to standardise the
approach and auto generate proxies and exceptions as
to make Twisted safe for the average Stackless Python
programmer.

Cheers,
Andrew

P.S - reference
http://www.artima.com/weblogs/viewpost.jsp?thread=156396

PBServer.py - is Bruce Eckel's server slightly
modified.



       
____________________________________________________________________________________
Got a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PBExample.py
Type: text/x-python
Size: 2589 bytes
Desc: pat706081052
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20070907/063141da/attachment.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PBServer.py
Type: text/x-python
Size: 662 bytes
Desc: 2825570039-PBServer.py
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20070907/063141da/attachment-0001.py 


More information about the Twisted-Python mailing list