class_docstr: An on-disk workspace that tracks disposable work directories inside it.
  If a process crashes or another event left stale directories behind,
  this will be detected and the directories purged.
class_docstr_tok: ["An","on-disk","workspace","that","tracks","disposable","work","directories","inside","it",".","If","a","process","crashes","or","another","event","left","stale","directories","behind",",","this","will","be","detected","and","the","directories","purged","."]
docstr: Try locking the given path, if it fails it's in use,
  otherwise the corresponding directory is deleted.
  
  Return True if the lock was stale.
docstr_tok: ["Try","locking","the","given","path",",","if","it","fails","it","'s","in","use",",","otherwise","the","corresponding","directory","is","deleted",".","Return","True","if","the","lock","was","stale","."]
code: def _check_lock_or_purge(self, lock_path):
      """
      Try locking the given path, if it fails it's in use,
      otherwise the corresponding directory is deleted.
  
      Return True if the lock was stale.
      """
      assert lock_path.endswith(DIR_LOCK_EXT)
      if lock_path in self._known_locks:
          # Avoid touching a lock that we know is already taken
          return False
      logger.debug("Checking lock file %r...", lock_path)
      lock = locket.lock_file(lock_path, timeout=0)
      try:
          lock.acquire()
      except locket.LockError:
          # Lock file still in use, ignore
          return False
      try:
          # Lock file is stale, therefore purge corresponding directory
          dir_path = lock_path[: -len(DIR_LOCK_EXT)]
          if os.path.exists(dir_path):
              logger.info(
                  "Found stale lock file and directory %r, purging",
                  dir_path,
              )
              self._purge_directory(dir_path)
      finally:
          lock.release()
      # Clean up lock file after we released it
      safe_unlink(lock_path)
      return True
  
imports: from __future__ import annotations
  import glob
  import logging
  import os
  import shutil
  import stat
  import sys
  import tempfile
  import weakref
  from typing import ClassVar
  import locket
  import dask
label_desc: Use image node_id 7 for calling the WorkSpace obj's underlying member method code with example usage: obj._check_lock_or_purge(lock_path) and returns: True, False, False