(self, cursor_ids, address, topology)
Send a kill cursors message with the given ids.
Send a kill cursors message with the given ids.
Send a kill cursors message with the given ids .
def _kill_cursors(self, cursor_ids, address, topology):
        """Send a kill cursors message with the given ids."""
        listeners = self._event_listeners
        publish = listeners.enabled_for_commands
        if address:
            # address could be a tuple or _CursorAddress, but
            # select_server_by_address needs (host, port).
            server = topology.select_server_by_address(tuple(address))
        else:
            # Application called close_cursor() with no address.
            server = topology.select_server(writable_server_selector)

        try:
            namespace = address.namespace
            db, coll = namespace.split('.', 1)
        except AttributeError:
            namespace = None
            db = coll = "OP_KILL_CURSORS"

        spec = SON([('killCursors', coll), ('cursors', cursor_ids)])
        with server.get_socket(self.__all_credentials) as sock_info:
            if sock_info.max_wire_version >= 4 and namespace is not None:
                sock_info.command(db, spec)
            else:
                if publish:
                    start = datetime.datetime.now()
                request_id, msg = message.kill_cursors(cursor_ids)
                if publish:
                    duration = datetime.datetime.now() - start
                    # Here and below, address could be a tuple or
                    # _CursorAddress. We always want to publish a
                    # tuple to match the rest of the monitoring
                    # API.
                    listeners.publish_command_start(
                        spec, db, request_id, tuple(address))
                    start = datetime.datetime.now()

                try:
                    sock_info.send_message(msg, 0)
                except Exception as exc:
                    if publish:
                        dur = ((datetime.datetime.now() - start) + duration)
                        listeners.publish_command_failure(
                            dur, message._convert_exception(exc),
                            'killCursors', request_id,
                            tuple(address))
                    raise

                if publish:
                    duration = ((datetime.datetime.now() - start) + duration)
                    # OP_KILL_CURSORS returns no reply, fake one.
                    reply = {'cursorsUnknown': cursor_ids, 'ok': 1}
                    listeners.publish_command_success(
                        duration, reply, 'killCursors', request_id,
                        tuple(address))
def _kill_cursors ( self , cursor_ids , address , topology ) : listeners = self . _event_listeners publish = listeners . enabled_for_commands if address : # address could be a tuple or _CursorAddress, but # select_server_by_address needs (host, port). server = topology . select_server_by_address ( tuple ( address ) ) else : # Application called close_cursor() with no address. server = topology . select_server ( writable_server_selector ) try : namespace = address . namespace db , coll = namespace . split ( '.' , 1 ) except AttributeError : namespace = None db = coll = "OP_KILL_CURSORS" spec = SON ( [ ( 'killCursors' , coll ) , ( 'cursors' , cursor_ids ) ] ) with server . get_socket ( self . __all_credentials ) as sock_info : if sock_info . max_wire_version >= 4 and namespace is not None : sock_info . command ( db , spec ) else : if publish : start = datetime . datetime . now ( ) request_id , msg = message . kill_cursors ( cursor_ids ) if publish : duration = datetime . datetime . now ( ) - start # Here and below, address could be a tuple or # _CursorAddress. We always want to publish a # tuple to match the rest of the monitoring # API. listeners . publish_command_start ( spec , db , request_id , tuple ( address ) ) start = datetime . datetime . now ( ) try : sock_info . send_message ( msg , 0 ) except Exception as exc : if publish : dur = ( ( datetime . datetime . now ( ) - start ) + duration ) listeners . publish_command_failure ( dur , message . _convert_exception ( exc ) , 'killCursors' , request_id , tuple ( address ) ) raise if publish : duration = ( ( datetime . datetime . now ( ) - start ) + duration ) # OP_KILL_CURSORS returns no reply, fake one. reply = { 'cursorsUnknown' : cursor_ids , 'ok' : 1 } listeners . publish_command_success ( duration , reply , 'killCursors' , request_id , tuple ( address ) )