def run(self): """Connect to manager and read/write messages from/to socket.""" logger.debug("Running manager client thread") if self.lock: self.lock.acquire() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: logger.debug("Connection to manager") sock.connect((self.host, self.port)) logger.debug("Connected to manager") if self.lock: self.lock.release() message_loop(sock, self.generate_message, self.on_message) finally: logger.debug("Closing socket") sock.close() if self.lock and self.lock.locked(): self.lock.release()
def handle(self): try: message_loop(self.request, self._generate_action, self._on_stats) except EOFError: print 'Client disconnected'