docstr: Acquire the locked filehandle
docstr_tok: ["Acquire","the","locked","filehandle"]
code: def acquire(
      self, timeout=None, check_interval=None, fail_when_locked=None
  ):
      """Acquire the locked filehandle"""
      if timeout is None:
          timeout = self.timeout
      if timeout is None:
          timeout = 0
  
      if check_interval is None:
          check_interval = self.check_interval
  
      if fail_when_locked is None:
          fail_when_locked = self.fail_when_locked
  
      # If we already have a filehandle, return it
      fh = self.fh
      if fh:
          return fh
  
      # Get a new filehandler
      fh = self._get_fh()
      try:
          # Try to lock
          fh = self._get_lock(fh)
      except exceptions.LockException as exception:
          # Try till the timeout has passed
          timeoutend = current_time() + timeout
          while timeoutend > current_time():
              # Wait a bit
              time.sleep(check_interval)
  
              # Try again
              try:
                  # We already tried to the get the lock
                  # If fail_when_locked is true, then stop trying
                  if fail_when_locked:
                      raise exceptions.AlreadyLocked(exception)
  
                  else:  # pragma: no cover
                      # We've got the lock
                      fh = self._get_lock(fh)
                      break
  
              except exceptions.LockException:
                  pass
  
          else:
              fh.close()
              # We got a timeout... reraising
              raise exceptions.LockException(exception)
  
      # Prepare the filehandle (truncate if needed)
      fh = self._prepare_fh(fh)
  
      self.fh = fh
      return fh
  
imports: import os
  import time
  import atexit
  import tempfile
  import contextlib
  from .None import exceptions
  from .None import constants
  from .None import portalocker
label_desc: Use image node_id 2 for calling the Lock obj's underlying member method code with example usage: obj.acquire(timeout, check_interval, fail_when_locked) and returns: fh, fh