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.
code: def __init__(
      self,
      filename: Filename,
      mode: str = "a",
      timeout: typing.Optional[float] = None,
      check_interval: float = DEFAULT_CHECK_INTERVAL,
      fail_when_locked: bool = DEFAULT_FAIL_WHEN_LOCKED,
      flags: constants.LockFlags = LOCK_METHOD,
      **file_open_kwargs,
  ):
      if "w" in mode:
          truncate = True
          mode = mode.replace("w", "a")
      else:
          truncate = False
  
      if timeout is None:
          timeout = DEFAULT_TIMEOUT
      elif not (flags & constants.LockFlags.NON_BLOCKING):
          warnings.warn(
              "timeout has no effect in blocking mode",
              stacklevel=1,
          )
  
      self.fh: typing.Optional[typing.IO] = None
      self.filename: str = str(filename)
      self.mode: str = mode
      self.truncate: bool = truncate
      self.timeout: float = timeout
      self.check_interval: float = check_interval
      self.fail_when_locked: bool = fail_when_locked
      self.flags: constants.LockFlags = flags
      self.file_open_kwargs = file_open_kwargs
  
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 1 to create a new Lock object from inherited base classes: LockBase with example: obj = Lock(filename, mode, timeout, check_interval, fail_when_locked, flags)