Hi guys,<br>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.<br><br>The problem:<br>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 appropriate.
<br><br>So I have something like this in my main method:<br><br>monitor = Monitor(server, port)<br>monitor.connect() <br clear="all"><br><br> def connect(self):<br> factory = pb.PBClientFactory()<br> reactor.connectTCP
(self.hostname, self.port, factory)<br> return factory.login(self.credentials).addCallback(<br> self._connected).addErrback(<br> self._catch_failure)<br><br>Then in self._connected I would like to start the chain of getting jobs/processing them/submitting jobs:
<br><br> def _connected(self, remoteobj):<br> self.remoteobj = remoteobj<br><br> for worker in self.workers:<br> self.get_jobs(worker).addCallback(<br> self._got_job, worker).addCallback(
<br> self.get_jobs, worker).addErrback(<br> self._catch_failure)<br><br>_got_job takes both a job and a worker and starts to process the job. Which for now returns a
defer.succeed().<br>This is the part where I stumble on though, the exact implementation of how to make it so that one calls back the other. <br>Any help would be appreciated. Please let me know also if you need more specific information.
<br><br>Thanks,<br>Yi