class_docstr: A profiler for resource use.
  
  Records the following each timestep
      1. Time in seconds since the epoch
      2. Memory usage in MB
      3. % CPU usage
  
  Examples
  --------
  
  >>> from operator import add, mul
  >>> from dask.threaded import get
  >>> dsk = {'x': 1, 'y': (add, 'x', 10), 'z': (mul, 'y', 2)}
  >>> with ResourceProfiler() as prof:
  ...     get(dsk, 'z')
  22
  
  These results can be visualized in a bokeh plot using the ``visualize``
  method. Note that this requires bokeh to be installed.
  
  >>> prof.visualize() # doctest: +SKIP
  
  You can activate the profiler globally
  
  >>> prof.register()
  
  If you use the profiler globally you will need to clear out old results
  manually.
  
  >>> prof.clear()
  
  Note that when used as a context manager data will be collected throughout
  the duration of the enclosed block. In contrast, when registered globally
  data will only be collected while a dask scheduler is active.
  
  >>> prof.unregister()
class_docstr_tok: ["A","profiler","for","resource","use",".","Records","the","following","each","timestep","1",".","Time","in","seconds","since","the","epoch","2",".","Memory","usage","in","MB","3",".","%","CPU","usage","Examples","--","--","--","--",">",">",">","from","operator","import","add",",","mul",">",">",">","from","dask.threaded","import","get",">",">",">","dsk","=","{","'","x","'",":","1",",","'","y","'",":","(","add",",","'","x","'",",","10",")",",","'","z","'",":","(","mul",",","'","y","'",",","2",")","}",">",">",">","with","ResourceProfiler","(",")","as","prof",":","...","get","(","dsk",",","'","z","'",")","22","These","results","can","be","visualized","in","a","bokeh","plot","using","the","``","visualize","``","method",".","Note","that","this","requires","bokeh","to","be","installed",".",">",">",">","prof.visualize","(",")","#","doctest",":","+SKIP","You","can","activate","the","profiler","globally",">",">",">","prof.register","(",")","If","you","use","the","profiler","globally","you","will","need","to","clear","out","old","results","manually",".",">",">",">","prof.clear","(",")","Note","that","when","used","as","a","context","manager","data","will","be","collected","throughout","the","duration","of","the","enclosed","block",".","In","contrast",",","when","registered","globally","data","will","only","be","collected","while","a","dask","scheduler","is","active",".",">",">",">","prof.unregister","(",")"]
code: def _finish(self, dsk, state, failed):
      if not self._entered:
          self._stop_collect()
  
imports: from __future__ import annotations
  from collections import namedtuple
  from itertools import starmap
  from multiprocessing import Pipe, Process, current_process
  from time import sleep
  from timeit import default_timer
  from dask.callbacks import Callback
  from dask.utils import import_required
label_desc: Use image node_id 8 for calling the ResourceProfiler obj's underlying member method code with example usage: obj._finish(dsk, state, failed) without return types