code: def remove_on_exception(dirname, remove=True):
      
      os.makedirs(dirname)
      try:
          yield
      except:
          if remove:
              shutil.rmtree(dirname, ignore_errors=True)
          raise
docs: Creates a directory, yields to the caller, and removes that directory
         if an exception is thrown.