[Twisted-Python] Understanding Deferreds/callback further
yqiang at gmail.com
Thu Nov 2 18:33:47 EST 2006
I am still having trouble writing programs that will make the most use of
deferreds. I will describe the problem I am trying to solve and the
solution I've tried.
I am trying to write a client that gets a job from a PB server, processes
it, submits the result and gets another job. I need to be able to do this
for multiple jobs (i.e. I need to be able to get 5 jobs, and start 5 similar
chains: get job --> work on job --> submit result --> get another job).
This looks like a perfectly solvable problem using deferreds since working
on the job might take a while and using callbacks seems to be the most
So I have something like this in my main method:
monitor = Monitor(server, port)
factory = pb.PBClientFactory()
reactor.connectTCP(self.hostname, self.port, factory)
Then in self._connected I would like to start the chain of getting
jobs/processing them/submitting jobs:
def _connected(self, remoteobj):
self.remoteobj = remoteobj
for worker in self.workers:
_got_job takes both a job and a worker and starts to process the job. Which
for now returns a defer.succeed().
This is the part where I stumble on though, the exact implementation of how
to make it so that one calls back the other.
Any help would be appreciated. Please let me know also if you need more
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python