class_docstr: A temporary work directory inside a WorkSpace.
class_docstr_tok: ["A","temporary","work","directory","inside","a","WorkSpace","."]
code: def __init__(self, workspace, name=None, prefix=None):
      assert name is None or prefix is None
  
      if name is None:
          self.dir_path = tempfile.mkdtemp(
              prefix=prefix, dir=workspace.base_dir
          )
      else:
          self.dir_path = os.path.join(workspace.base_dir, name)
          os.mkdir(self.dir_path)  # it shouldn't already exist
  
      if is_locking_enabled():
          try:
              self._lock_path = os.path.join(
                  self.dir_path + DIR_LOCK_EXT
              )
              assert not os.path.exists(self._lock_path)
              logger.debug("Locking %r...", self._lock_path)
              # Avoid a race condition before locking the file
              # by taking the global lock
              try:
                  with workspace._global_lock():
                      self._lock_file = locket.lock_file(
                          self._lock_path
                      )
                      self._lock_file.acquire()
              except OSError:
                  logger.exception(
                      "Could not acquire workspace lock on "
                      "path: %s ."
                      "Continuing without lock. "
                      "This may result in workspaces not being "
                      "cleaned up",
                      self._lock_path,
                      exc_info=True,
                  )
                  self._lock_file = None
          except Exception:
              shutil.rmtree(self.dir_path, ignore_errors=True)
              raise
          workspace._known_locks.add(self._lock_path)
  
          self._finalizer = weakref.finalize(
              self,
              self._finalize,
              workspace,
              self._lock_path,
              self._lock_file,
              self.dir_path,
          )
      else:
          self._finalizer = weakref.finalize(
              self, self._finalize, workspace, None, None, self.dir_path
          )
  
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 1 to create a new WorkDir object  with example: obj = WorkDir(workspace, name, prefix)