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

Nick Johnson Nick.Johnson at ed.ac.uk
Fri Jul 19 02:19:26 MDT 2013


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).

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.

Cheers,
-Nick.


On 18/07/13 18:07, Laurens Van Houtven wrote:
> Hi Nick,
> 
> You're pretty much there already. Instantiate a ClientFactory that holds
> all the necessary state. By default, your protocol will have access to
> that state through its factory attribute (unless you override the
> Factory's buildProtocol method).
> 
> cheers
> lvh

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.





More information about the Twisted-Python mailing list