'Cancels all pending tasks and closes all cursors. Then, it closes the connection.'

@blocking_call_on_reactor_thread
def close(self):

    self.cancel_all_pending_tasks()
    with self._cursor_lock:
        for cursor in self._cursor_table.itervalues():
            cursor.close()
        self._cursor_table = {}
        self._connection.close()
        self._connection = None
