[Twisted-Python] callback style question

Justin Johnson justinjohnson at fastmail.fm
Fri Jun 13 14:24:41 MDT 2003


Hi,

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
server, and then something on another if the first thing was successful. 
It seems like I'd have quite a chain of callbacks, but maybe this is
normal.  Below I posted the relevant code snippets of what I'm currently
doing on the client side.

Do I need to define methods for every step in the chain?  Would someone
mind giving me advice on how something like this should be written?

Thanks much.
-Justin



def connectToServer(server):
	# s = xmlrpclib.Server('http://%s:%s/' % (server, config.portNumber) )
	s = xmlrpclib.ServerProxy('http://%s:%s' % (server, config.portNumber), BasicAuthTransport(config.adminUser,config.adminPassword))
	return s

# Subcommand: mkvob
def doMkvob2(options):
	original_site = options["original"]
	group = options["group"]
	vobs = options["vobs"].split(",")
	sites = options["sites"].split(",")

	#s = connectToServer(config.siteToServer[original_site])
	#s = connectToTwistedServer(config.siteToServer[original_site])
	s = xmlrpclib.ServerProxy('http://%s:%s' % (server, config.portNumber), BasicAuthTransport(config.adminUser,config.adminPassword))

	print "Successfully connected to %s (%s)." % (original_site, config.siteToServer[original_site])
	print "Calling remote mkvob ..."
	results = s.mkvob(vobs, group)
	results += s.mkReplicaExport(vobs,sites)
	results += s.renameReplica(vobs, "original", original_site)
	results += s.exportReplica(vobs,sites)
	for site in sites:
		thatServer = connectToServer(config.siteToServer[site])
		results += thatServer.mkReplicaImport(vobs)
		results += thatServer.importReplica(vobs)
		results += thatServer.applyTriggers(vobs)
	print "[output]\n%s[/output]" % results




More information about the Twisted-Python mailing list