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?