class_docstr: Lock manager with built-in timeout
  
  Args:
      filename: filename
      mode: the open mode, 'a' or 'ab' should be used for writing. When mode
          contains `w` the file will be truncated to 0 bytes.
      timeout: timeout when trying to acquire a lock
      check_interval: check interval while waiting
      fail_when_locked: after the initial lock failed, return an error
          or lock the file. This does not wait for the timeout.
      **file_open_kwargs: The kwargs for the `open(...)` call
  
  fail_when_locked is useful when multiple threads/processes can race
  when creating a file. If set to true than the system will wait till
  the lock was acquired and then return an AlreadyLocked exception.
  
  Note that the file is opened first and locked later. So using 'w' as
  mode will result in truncate _BEFORE_ the lock is checked.
docstr: Acquire the locked filehandle
docstr_tok: ["Acquire","the","locked","filehandle"]
code: def acquire(
      self,
      timeout: typing.Optional[float] = None,
      check_interval: typing.Optional[float] = None,
      fail_when_locked: typing.Optional[bool] = None,
  ) -> typing.IO:
      """Acquire the locked filehandle"""
  
      fail_when_locked = coalesce(
          fail_when_locked, self.fail_when_locked
      )
  
      if (
          not (self.flags & constants.LockFlags.NON_BLOCKING)
          and timeout is not None
      ):
          warnings.warn(
              "timeout has no effect in blocking mode",
              stacklevel=1,
          )
  
      # If we already have a filehandle, return it
      fh: typing.Optional[typing.IO] = self.fh
      if fh:
          return fh
  
      # Get a new filehandler
      fh = self._get_fh()
  
      def try_close():  # pragma: no cover
          # Silently try to close the handle if possible, ignore all issues
          if fh is not None:
              with contextlib.suppress(Exception):
                  fh.close()
  
      exception = None
      # Try till the timeout has passed
      for _ in self._timeout_generator(timeout, check_interval):
          exception = None
          try:
              # Try to lock
              fh = self._get_lock(fh)
              break
          except exceptions.LockException as exc:
              # Python will automatically remove the variable from memory
              # unless you save it in a different location
              exception = exc
  
              # We already tried to the get the lock
              # If fail_when_locked is True, stop trying
              if fail_when_locked:
                  try_close()
                  raise exceptions.AlreadyLocked(exception) from exc
  
              # Wait a bit
  
      if exception:
          try_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 abc
  import atexit
  import contextlib
  import logging
  import os
  import pathlib
  import random
  import tempfile
  import time
  import typing
  import warnings
  from .None import constants, exceptions, 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