twisted reactor stops too early

Posted by pygabriel on Stack Overflow See other posts from Stack Overflow or by pygabriel
Published on 2010-05-10T16:24:14Z Indexed on 2010/05/10 17:14 UTC
Read the original article Hit count: 294

Filed under:
|
|

I'm doing a batch script to connect to a tcp server and then exiting. My problem is that I can't stop the reactor, for example:

cmd = raw_input("Command: ")

# custom factory, the protocol just send a line
reactor.connectTCP(HOST,PORT, CommandClientFactory(cmd) 
d = defer.Deferred()

d.addCallback(lambda x: reactor.stop())    
reactor.callWhenRunning(d.callback,None)
reactor.run()

In this code the reactor stops before that the tcp connection is done and the cmd is passed.

How can I stop the reactor after that all the operation are finished?

© Stack Overflow or respective owner

Related posts about twisted

Related posts about python