def release(self, key: str) -> Optional[str]:
        """
        Release the lock.

        Noop if not locked.
        :param key: the name of the lock to release
        :return: the name of the released lock, or `None` if no lock was released
        :raises InvalidKeyError: if the `key` is not valid
        """
        ConsulLockManager.validate_key(key)

        key_value = self.consul_client.kv.get(key)[1]
        if key_value is None:
            logger.info(f"No lock found")
            return None

        lock_information = json.loads(key_value["Value"].decode("utf-8"), cls=ConsulLockInformationJSONDecoder)
        logger.info(f"Destroying the session {lock_information.session_id} that is holding the lock")
        unlocked = self.consul_client.session.destroy(session_id=lock_information.session_id)
        # This instance might be managing the removed session
        try:
            self._acquiring_session_ids.remove(lock_information.session_id)
        except KeyError:
            pass

        logger.info("Unlocked" if unlocked else "Went to unlock but was already released upon sending request")
        return key
def release ( self , key : str ) -> Optional [ str ] : ConsulLockManager . validate_key ( key ) key_value = self . consul_client . kv . get ( key ) [ 1 ] if key_value is None : logger . info ( f"No lock found" ) return None lock_information = json . loads ( key_value [ "Value" ] . decode ( "utf-8" ) , cls = ConsulLockInformationJSONDecoder ) logger . info ( f"Destroying the session {lock_information.session_id} that is holding the lock" ) unlocked = self . consul_client . session . destroy ( session_id = lock_information . session_id ) try : self . _acquiring_session_ids . remove ( lock_information . session_id ) except KeyError : pass logger . info ( "Unlocked" if unlocked else "Went to unlock but was already released upon sending request" ) return key
Release the lock.

        Noop if not locked.
        :param key: the name of the lock to release
        :return: the name of the released lock, or `None` if no lock was released
        :raises InvalidKeyError: if the `key` is not valid