class_docstr: Stateful object able to manage temporary folder and pickles
  
  It exposes:
  - a per-context folder name resolving API that memmap-based reducers will
    rely on to know where to pickle the temporary memmaps
  - a temporary file/folder management API that internally uses the
    resource_tracker.
class_docstr_tok: ["Stateful","object","able","to","manage","temporary","folder","and","pickles","It","exposes",":","-","a","per-context","folder","name","resolving","API","that","memmap-based","reducers","will","rely","on","to","know","where","to","pickle","the","temporary","memmaps","-","a","temporary","file\/folder","management","API","that","internally","uses","the","resource_tracker","."]
docstr: Clean temporary resources created by a process-based pool
docstr_tok: ["Clean","temporary","resources","created","by","a","process-based","pool"]
code: def _clean_temporary_resources(
      self, context_id=None, force=False, allow_non_empty=False
  ):
      """Clean temporary resources created by a process-based pool"""
      if context_id is None:
          # Iterates over a copy of the cache keys to avoid Error due to
          # iterating over a changing size dictionary.
          for context_id in list(self._cached_temp_folders):
              self._clean_temporary_resources(
                  context_id,
                  force=force,
                  allow_non_empty=allow_non_empty,
              )
      else:
          temp_folder = self._cached_temp_folders.get(context_id)
          if temp_folder and os.path.exists(temp_folder):
              for filename in os.listdir(temp_folder):
                  if force:
                      # Some workers have failed and the ref counted might
                      # be off. The workers should have shut down by this
                      # time so forcefully clean up the files.
                      resource_tracker.unregister(
                          os.path.join(temp_folder, filename), "file"
                      )
                  else:
                      resource_tracker.maybe_unlink(
                          os.path.join(temp_folder, filename), "file"
                      )
  
              # When forcing clean-up, try to delete the folder even if some
              # files are still in it. Otherwise, try to delete the folder
              allow_non_empty |= force
  
              # Clean up the folder if possible, either if it is empty or
              # if none of the files in it are in used and allow_non_empty.
              try:
                  delete_folder(
                      temp_folder, allow_non_empty=allow_non_empty
                  )
                  # Forget the folder once it has been deleted
                  self._cached_temp_folders.pop(context_id, None)
                  resource_tracker.unregister(temp_folder, "folder")
  
                  # Also cancel the finalizers  that gets triggered at gc.
                  finalizer = self._finalizers.pop(context_id, None)
                  if finalizer is not None:
                      atexit.unregister(finalizer)
  
              except OSError:
                  # Temporary folder cannot be deleted right now.
                  # This folder will be cleaned up by an atexit
                  # finalizer registered by the memmapping_reducer.
                  pass
  
imports: from mmap import mmap
  import errno
  import os
  import stat
  import threading
  import atexit
  import tempfile
  import time
  import warnings
  import weakref
  from uuid import uuid4
  from multiprocessing import util
  from pickle import whichmodule, loads, dumps, HIGHEST_PROTOCOL, PicklingError
  from .numpy_pickle import dump, load, load_temporary_memmap
  from .backports import make_memmap
  from .disk import delete_folder
  from .externals.loky.backend import resource_tracker
label_desc: Use image node_id 6 for calling the TemporaryResourcesManager obj's underlying member method code with example usage: obj._clean_temporary_resources(context_id, force, allow_non_empty) without return types