code: def __init__(self, cleanup_m, cache_dir):
      if cache_dir is not None:
          self.lock_file = os.path.join(cache_dir, "lock")
  
          attempts = 0
          while True:
              try:
                  self.fd = os.open(
                      self.lock_file,
                      os.O_CREAT | os.O_WRONLY | os.O_EXCL,
                  )
                  break
              except OSError:
                  pass
  
              # This value was chosen based on the py-filelock package:
              # https://github.com/tox-dev/py-filelock/blob/a6c8fabc4192fa7a4ae19b1875ee842ec5eb4f61/src/filelock/_api.py#L113
              # When running pyopencl in an application with multiple ranks
              # that share a cache_dir, higher timeouts can lead to
              # application stalls even with low numbers of ranks.
              # cf. https://github.com/inducer/pyopencl/pull/504
              wait_time_seconds = 0.05
  
              # Warn every 10 seconds if not able to acquire lock
              warn_attempts = int(10 / wait_time_seconds)
  
              # Exit after 60 seconds if not able to acquire lock
              exit_attempts = int(60 / wait_time_seconds)
  
              from time import sleep
  
              sleep(wait_time_seconds)
  
              attempts += 1
  
              if attempts % warn_attempts == 0:
                  from warnings import warn
  
                  warn(
                      f"Could not obtain cache lock--delete '{self.lock_file}' "
                      "if necessary",
                      stacklevel=2,
                  )
  
              if attempts > exit_attempts:
                  raise RuntimeError(
                      "waited more than one minute "
                      "on the lock file '%s'"
                      "--something is wrong" % self.lock_file
                  )
  
          cleanup_m.register(self)
  
imports: import re
  import os
  import sys
  from dataclasses import dataclass
  from typing import List, Optional, Tuple
  import pyopencl._cl
  import logging
  import hashlib
label_desc: Use image node_id 1 to create a new CacheLockManager object from inherited base classes: CleanupBase with example: obj = CacheLockManager(cleanup_m, cache_dir)