'Use this in order to avoid deadlocking the event loop thread.
When the operation completes, `callback` will be called with
two arguments: this connection and an Exception if an error
occurred, otherwise :const:`None`.
This method will always increment :attr:`.in_flight` attribute, even if
it doesn\'t need to make a request, just to maintain an
":attr:`.in_flight` is incremented" invariant.'

def set_keyspace_async(self, keyspace, callback):

    while True:
        with self.lock:
            if (self.in_flight < self.max_request_id):
                self.in_flight += 1
                break
        time.sleep(0.001)
    if ((not keyspace) or (keyspace == self.keyspace)):
        callback(self, None)
        return
    query = QueryMessage(query=('USE    "%s"' % (keyspace,)), consistency_level=ConsistencyLevel.ONE)
    def process_result(result):
        if isinstance(result, ResultMessage):
            self.keyspace = keyspace
            callback(self, None)
        elif isinstance(result, InvalidRequestException):
            callback(self, result.to_exception())
        else:
            callback(self, self.defunct(ConnectionException(('Problem    while    setting    keyspace:    %r' % (result,)), self.host)))
    request_id = self.get_request_id()
    self.send_msg(query, request_id, process_result)
