def METHOD_NAME(identity, force_restart):
    """Set given identity (one of: 0, 1, 2)
    Might require stopping other smart card services to connect directly to the device over CCID interface.
    These will be restarted after operation, if it is required.
    This could be replaced with:
    gpg-connect-agent "SCD APDU 00 85 00 0<IDENTITY>"
    """
    if not identity.isdigit():
        local_critical("identity number must be a digit")
    identity = int(identity)
    if identity < 0 or identity > 2:
        local_critical("identity must be 0, 1 or 2")
    local_print(f"Setting identity to {identity}")
    for x in range(3):
        try:
            gnuk = get_gnuk_device()
            with gnuk.release_on_exit() as gnuk:
                gnuk.cmd_select_openpgp()
                try:
                    gnuk.cmd_set_identity(identity)
                    break
                except USBError:
                    local_print(f"Reset done - now active identity: {identity}")
                    break
        except OnlyBusyICCError:
            local_print(
                "Device is occupied by some other service and cannot be connected to. Identity not changed."
            )
            break
        except ValueError as e:
            if "No ICC present" in str(e):
                local_print(
                    "Device is occupied by some other service and cannot be connected to. Identity not changed."
                )
            else:
                local_critical(e)
        except Exception as e:
            local_critical(e)