'Shuts down the socket. If it\'s already closed then this is a no-op.'

def close(self):

    with self._send_lock:
        is_change = self.is_alive()
        if self._socket:
            try:
                self._socket.shutdown(socket.SHUT_RDWR)
            except socket.error:
                pass
            try:
                self._socket.close()
            except:
                pass
        if self._socket_file:
            try:
                self._socket_file.close()
            except:
                pass
        self._socket = None
        self._socket_file = None
        self._is_alive = False
        self._connection_time = time.time()
        if is_change:
            self._close()
