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: Create base_dir if it doesn't exist.
  If base_dir already exists but it's not writeable, change the name.
docstr_tok: ["Create","base_dir","if","it","does","n't","exist",".","If","base_dir","already","exists","but","it","'s","not","writeable",",","change","the","name","."]
code: def _init_workspace(self, base_dir: str) -> str:
      """Create base_dir if it doesn't exist.
      If base_dir already exists but it's not writeable, change the name.
      """
      base_dir = os.path.abspath(base_dir)
      try_dirs = [base_dir]
      # Note: WINDOWS constant doesn't work with `mypy --platform win32`
      if sys.platform != "win32":
          # - os.getlogin() raises OSError on containerized environments
          # - os.getuid() does not exist in Windows
          try_dirs.append(f"{base_dir}-{os.getuid()}")
  
      for try_dir in try_dirs:
          try:
              os.makedirs(try_dir)
          except FileExistsError:
              try:
                  with tempfile.TemporaryFile(dir=try_dir):
                      pass
              except PermissionError:
                  continue
          return try_dir
  
      # If we reached this, we're likely in a containerized environment where /tmp
      # has been shared between containers through a mountpoint, every container
      # has an external $UID, but the internal one is the same for all.
      return tempfile.mkdtemp(prefix=base_dir + "-")
  
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 2 for calling the WorkSpace obj's underlying member method code with example usage: obj._init_workspace(base_dir) and returns: tempfile, try_dir