code: def lock(library, session, lock_type, timeout, requested_key=None):
      
      if lock_type == constants.AccessModes.exclusive_lock:
          requested_key = None
          access_key = None
      else:
          access_key = create_string_buffer(256)
      ret = library.viLock(session, lock_type, timeout, requested_key, access_key)
      if access_key is None:
          return None, ret
      else:
          return access_key.value, ret
docs: Establishes an access mode to the specified resources.
  
      Corresponds to viLock function of the VISA library.
  
      :param library: the visa library wrapped by ctypes.
      :param session: Unique logical identifier to a session.
      :param lock_type: Specifies the type of lock requested, either constants.AccessModes.exclusive_lock
                        or constants.AccessModes.shared_lock.
      :param timeout: Absolute time period (in milliseconds) that a resource waits to get unlocked by the
                      locking session before returning an error.
      :param requested_key: This parameter is not used and should be set to VI_NULL when lockType is VI_EXCLUSIVE_LOCK.
      :return: access_key that can then be passed to other sessions to share the lock, return value of the library call.
      :rtype: str, :class:`pyvisa.constants.StatusCode`