[Twisted-Python] perspective broker question

Christopher Armstrong radix at twistedmatrix.com
Tue Apr 22 11:39:11 EDT 2003


On 2003.04.22 05:13, Egor Cheshkov wrote:
> Hello everyone! Newbie question. I need to make a blocking call in 
> perspective_X() method. So I put my call into separate thread and get a 
> deferred wich will be called back when data available. But deferred 
> could not be returned from perspective_X method (not sure). 

Yes, you can return a Deferred from a perspective_ method and it will
do the right thing.

Also, you can do something like this

    def perspective_X(self):
        #doSomeOperation here returns a Deferred
        return doSomeOperation().addCallbacks(self.mungeIt, self.ohCrap)

... And implement mungeIt and ohCrap to take the result, munge it in some
useful way, and return it. The return value will be used as the result
on the client side (who originally did callRemote('X'))
This way you can do some processing on the result of your operation
before the client gets it, if you need to.

For more info on Deferreds, http://twistedmatrix.com/documents/howto/defer

-- 
 Twisted | Christopher Armstrong: International Man of Twistery
  Radix  |          Release Manager,  Twisted Project
---------+     http://twistedmatrix.com/users/radix.twistd/




More information about the Twisted-Python mailing list