[Twisted-Python] Best way to trigger a future connection with data

Laurens Van Houtven _ at lvh.io
Fri Jul 19 02:25:15 MDT 2013


On Fri, Jul 19, 2013 at 10:19 AM, Nick Johnson <Nick.Johnson at ed.ac.uk>wrote:

> Thanks lvh,
>
> I did have to override the buildProtocol method in the Factory but I
> then set Protocol.factory to be equal to the Factory (ie,
> myprotocol.factory=self).
>

You could (perhaps should) do this by calling
ClientFactory.buildProtocol(self, addr).


> I'm still stuck however with what to do when I get more complex than
> this simple case. For example, I use a callingLoop to call multiple
> connections with a 0.1 second interval to launch jobs and each of those
> connections does as mentioned by setting up a future connection to
> retrieve the output, say 10 seconds later. There is going to be some
> overlap, ie I might have launched 100 new jobs before the first one
> fires it's task.callLater.
>
> Storing state in the factory class doesn't work in this case because
> each new connection wont know whether to initiate a job or retrieve
> output as I cannot pass it this extra information.
>

I don't understand why not. Could you elaborate?

Either way, it seems to me that the API should be:

d = scheduleJob()
d.addCallback(getJob)

That is: only get the job once it has been scheduled. getJob would probably
have to be split up into something that delays (consider delayLater), and
something that actually gets the job.

cheers
lvh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130719/2d1407a6/attachment.html>


More information about the Twisted-Python mailing list