[Twisted-Python] PB/Remote Object/Deferred question

John Crawford cyclops at speakeasy.net
Wed Sep 9 12:39:03 EDT 2009


I'm trying to understand the Perspective Broker, reading over the 
on-site documentation, specifically the article:

http://twistedmatrix.com/projects/core/documentation/howto/pb-usage.html

and there is a section about the callRemote() function that I really 
don't understand :)

First, consider these three lines:

d = factory.getRootObject()
d.addCallback(lambda object: object.callRemote("echo", "hello network"))
d.addCallback(lambda echo: 'server echoed: '+echo)

Second, the documentation says, "...object.callRemote() returns a 
Deferred. Assuming the remote method was run without causing an 
exception (including an attempt to invoke an unknown method), the 
callback attached to that Deferred will be invoked with any objects 
that were returned by the remote method call."

If I read this correctly, callRemote() returns a whole new Deferred 
object, which is *not* the same as the 'd' Deferred object we already 
have. So that *new* Deferred should be the one that the next callback 
(line 3) is added to, since the next callback is based on the success 
of the callRemote(). So wouldn't these be the correct lines:

d = factory.getRootObject()
d2 = d.addCallback(lambda object: object.callRemote("echo", "hello network"))
d2.addCallback(lambda echo: 'server echoed: '+echo)


Thanks in advance for any clarification.

John C>







More information about the Twisted-Python mailing list