code: def temp_dir(dir, erase_after=False, with_sentinel=True):
      created_by_me = False
      if not os.path.exists(dir):
          if os.pardir in dir:
              raise RuntimeError("workdir contains os.pardir ('..')")
          if erase_after and with_sentinel:
              closest_dir, fn = get_closest_dir(dir)
              sentinel = os.path.join(closest_dir, fn + ".inuse")
              open(sentinel, "w").close()
          os.makedirs(dir)
          created_by_me = True
      else:
          assert os.path.isdir(dir)
      yield
      if erase_after and created_by_me:
          # erase all files in workdir
          shutil.rmtree(dir)
          if with_sentinel:
              # put dir back as starting point for recursive remove
              os.mkdir(dir)
  
              # also try to erase any other empty directories up to
              # sentinel file
              os.removedirs(dir)
  
              # remove sentinel file
              os.remove(sentinel)
  
imports: import datetime
  import numpy
  import logging
  import os
  import shutil
  import sys
  import uuid
  import numpy
  from .None import pyll
  from contextlib import contextmanager
label_desc: Use image node_id 16 for calling a global function with example usage: temp_dir(dir, erase_after, with_sentinel) without return types