Re: [Twisted-Python] Wrapping a Perspective
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
participants (1)
-
Andrew Francis