[Twisted-Python] callback style question

Itamar Shtull-Trauring itamar at itamarst.org
Fri Jun 13 16:28:30 EDT 2003

On Fri, 13 Jun 2003 14:24:41 -0600
"Justin Johnson" <justinjohnson at fastmail.fm> wrote:

> I wrote an xmlrpc service using twisted for the server portion but
> using xmlrpclib on the client side to connect.  It is working
> beautifully, and greatly simplifying my job.  However, now I decided
> that I'd like to take advantage of Deferred's on the client side so
> that I can initiate multiple requests at once.  These requests involve
> doing something on one

Using Deferreds wont magically make requests run at once. You'd need to
use twisted event loop - i.e. the reactor - on the client side. xmlrpc
requests would need to be run by the xmlrpc client support in
twisted.web.xmlrpc, e.g.:

d = xmlrpc.Proxy("http://localhost:8080/").callRemote("foo.bar", 1, 2)
instead of 
xmlrpclib.ServerProxy("http://localhost:8080").foo.bar(1, 2)

For callbacks, yes, you need to use a function, bit that can be a lmbda

d.addCallback(int).addCallback(lambda x: x*2) # convert to int and
multiply by 2

Itamar Shtull-Trauring    http://itamarst.org/
http://www.zoteca.com -- Python & Twisted consulting

More information about the Twisted-Python mailing list