Example #1
0
def _maybe_register_license(path=None):
    """Registers the MuJoCo license if not already registered.

  Args:
    path: Optional custom path to license key file.

  Raises:
    Error: If the license could not be registered.
  """
    with _REGISTRATION_LOCK:
        global _REGISTERED
        if not _REGISTERED:
            if path is None:
                path = util.get_mjkey_path()
            # TODO(b/176220357): Repeatedly activating a trial license results in
            #                    errors (for example this could happen if
            #                    `mj_activate` was already called by another library
            #                    within the same process). To avoid such errors we
            #                    unconditionally deactivate any active licenses before
            #                    calling `mj_activate`.
            mjlib.mj_deactivate()
            result = mjlib.mj_activate(util.to_binary_string(path))
            if result == 1:
                _REGISTERED = True
                # Internal analytics of mj_activate.
            elif result == 0:
                raise Error("Could not register license.")
            else:
                raise Error(
                    "Unknown registration error (code: {})".format(result))
Example #2
0
def _maybe_register_license(path=None):
  """Registers the MuJoCo license if not already registered.

  Args:
    path: Optional custom path to license key file.

  Raises:
    Error: If the license could not be registered.
  """
  global _REGISTERED
  if not _REGISTERED:
    if path is None:
      path = util.get_mjkey_path()
    result = mjlib.mj_activate(util.to_binary_string(path))
    if result == 1:
      _REGISTERED = True
    elif result == 0:
      raise Error("Could not register license.")
    else:
      raise Error("Unknown registration error (code: {})".format(result))