code: def _safe_acquire_lock(self, lock: RefreshLock):
      last_touch_seen = None
      prev_touch_time = None
      last_owner_id = None
      while True:
          try:
              lock.acquire()
              logger.debug("Lock is acquired!")
              break
          except TimeoutError:
              owner_id = lock.owner_id()
              if owner_id != last_owner_id:
                  logger.debug(f"Lock has been acquired by {owner_id}")
                  last_owner_id = owner_id
                  prev_touch_time = None
              else:  # same holder as from prev. iteration
                  last_touch_time = lock.last_refresh_time()
                  if last_touch_time != prev_touch_time:
                      prev_touch_time = last_touch_time
                      last_touch_seen = time.time()
                      logger.debug(
                          f"Lock has been refreshed. Touch time: {last_touch_time}"
                      )
                      continue
                  assert last_touch_seen is not None
                  if (
                      time.time() - last_touch_seen
                      > RefreshLock.GRACE_PERIOD
                  ):
                      logger.debug(
                          "Grace period exceeded. Force-acquiring the lock."
                      )
                      with lock.meta_lock():
                          # double check holder ID
                          if (
                              lock.owner_id() != last_owner_id
                          ):  # someone else grabbed lock
                              continue
                          else:
                              lock.force_release()
                              try:
                                  lock.acquire()
                                  logger.debug(
                                      "lock has been forcefully acquired!"
                                  )
                                  break
                              except TimeoutError:
                                  continue
                  else:
                      logger.debug(
                          f"Countdown to force-acquire lock. "
                          f"Time remaining: {RefreshLock.GRACE_PERIOD - (time.time() - last_touch_seen)}"
                      )
  
imports: import contextlib
  import time
  import datetime
  import pytz
  import logging
  import os
  from threading import Thread
  from pathlib import Path
  from typing import Iterable
  from aim.sdk.repo import Repo
  from aim.sdk.run_status_watcher import Event
  from aim.storage.locking import RefreshLock
label_desc: Use image node_id 12 for calling the RepoIndexManager obj's underlying member method code with example usage: obj._safe_acquire_lock(lock) without return types