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","."]
code: def _purge_leftovers(self):
      if not is_locking_enabled():
          return []
  
      # List candidates with the global lock taken, to avoid purging
      # a lock file that was just created but not yet locked
      # (see WorkDir.__init__)
      lock = self._global_lock(timeout=0)
      try:
          lock.acquire()
      except locket.LockError:
          # No need to waste time here if someone else is busy doing
          # something on this workspace
          return []
      else:
          try:
              candidates = list(self._list_unknown_locks())
          finally:
              lock.release()
  
      # No need to hold the global lock here, especially as purging
      # can take time.  Instead take the purge lock to avoid two
      # processes purging at once.
      purged = []
      lock = self._purge_lock(timeout=0)
      try:
          lock.acquire()
      except locket.LockError:
          # No need for two processes to purge one after another
          pass
      else:
          try:
              for path in candidates:
                  if self._check_lock_or_purge(path):
                      purged.append(path)
          finally:
              lock.release()
      return purged
  
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 5 for calling the WorkSpace obj's underlying member method code with example usage: obj._purge_leftovers() and returns: purged, list, list