def all_connections(self): """Returns a generator over all current connection objects""" for i in _xrange(self.num_patterns): for c in self._available_connections[i]: yield c for c in self._in_use_connections[i]: yield c
def execute_command(self, *args, **options): """Execute a command and return a parsed response""" pool = self.connection_pool command_name = args[0] for i in _xrange(self.execution_attempts): connection = pool.get_connection(command_name, **options) try: connection.send_command(*args) res = self.parse_response(connection, command_name, **options) pool.release(connection) return res except ConnectionError: pool.purge(connection) if i >= self.execution_attempts - 1: raise
def execute_command(self, *args, **options): """Execute a command and return a parsed response""" pool = self.connection_pool command_name = args[0] for i in _xrange(self.execution_attempts): connection = pool.get_connection(command_name, **options) try: connection.send_command(*args) res = self.parse_response(connection, command_name, **options) pool.release(connection) return res # If anything goes wrong in .send_command() or .parse_response(), # and we don't catch it, this connection will never be returned to # the pool, and thus will leak. # # So, catch *everything* here except SystemExits and # KeyboardInterrupts. except Exception: pool.purge(connection) if i >= self.execution_attempts - 1: raise