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

Nick Johnson Nick.Johnson at ed.ac.uk
Thu Jul 18 10:59:37 MDT 2013


Hi,

I'm porting some code to twisted and got a little stuck. The current
(non-twisted) code connects to a server, gives it some data (a job to
do), gets a job-id and then terminates the connection. Sometime later,
it reconnects and gets the output using the job-id.

I've a factory and protocol set up, with buildProtocol over-riden in the
Factory class to supply some extra data to each Protocol instance when
it's created. This is fine when I submit a job as I can call a factory
function to generate the required data (ie the job to do). My problem is
how to initiate a connection at some point in the future AND pass it
some specific info (ie the job-id) for it to pass to the server.

I start the connections using task.callingLoop and reactor.connectTCP so
my first guess was to add: task.callLater(time, reactor.connectTCP, ...)
to the connectionLost method of my Protocol. However, I cannot see how
to pass in any extra information (ie the job-id) this way? I know I can
store state in the Factory, so I guess I just need to know how to pass
this to a scheduled invocation of the Protocol.

Is anyone able to point me in the right direction here?

Cheers,
-Nick.
-- 
Nick Johnson, Applications Developer, EPCC
2407 JCMB, King's Buildings, Mayfield Road, Edinburgh, EH9 3JF
e: Nick.Johnson at ed.ac.uk t: 0131 651 3388

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




More information about the Twisted-Python mailing list