Twisted PB: returning result as soon as ready

jacopo jacopo.pecci at gmail.com
Fri Sep 25 15:25:25 CEST 2009


In the following chunk of code the CLIENT receives both the results
from “compute” at the same time (i.e. when the second one has
finished). This way it cannot start “elaborateResult” on the first
result while the SERVER is still running the second “compute”.
How could I get the first result as soon as ready and therefore
parallelize things?
thanks, Jacopo

SERVER:

fibo=Fibonacci()
fact=pb.PBServerFactory(fibo)
reactor.listenTCP(port,  fact)
reactor.run()

CLIENT:

fact=pb.PBClientFactory()
reactor.connectTCP(host, port,   fact)
d=fact.getRootObject()
n1=10000
d.addCallback(lambda obj: obj.callRemote("compute", n1))
d.addCallback(elaborateResult)

d2=fact.getRootObject()
n2=10000
d2.addCallback(lambda obj: obj.callRemote("compute",  n2))
d2.addCallback(elaborateResult)

reactor.run()



More information about the Python-list mailing list