def clientConnectionLost(self, connector, reason): print 'Connection lost. Reason:', reason if reactor.running: reactor.stop()