class_docstr: Class which supports object finalization using weakrefs
class_docstr_tok: ["Class","which","supports","object","finalization","using","weakrefs"]
docstr: Run the callback unless it has already been called or cancelled
docstr_tok: ["Run","the","callback","unless","it","has","already","been","called","or","cancelled"]
code: def __call__(
      self,
      wr=None,
      # Need to bind these locally because the globals can have
      # been cleared at shutdown
      _finalizer_registry=_finalizer_registry,
      sub_debug=sub_debug,
      getpid=os.getpid,
  ):
      """
      Run the callback unless it has already been called or cancelled
      """
      try:
          del _finalizer_registry[self._key]
      except KeyError:
          sub_debug("finalizer no longer registered")
      else:
          if self._pid != getpid():
              sub_debug("finalizer ignored because different process")
              res = None
          else:
              sub_debug(
                  "finalizer calling %s with args %s and kwargs %s",
                  self._callback,
                  self._args,
                  self._kwargs,
              )
              res = self._callback(*self._args, **self._kwargs)
          self._weakref = (
              self._callback
          ) = self._args = self._kwargs = self._key = None
          return res
  
imports: import os
  import itertools
  import sys
  import weakref
  import atexit
  import threading
  from subprocess import _args_from_interpreter_flags
  from .None import process
label_desc: Use image node_id 2 for calling the Finalize obj's underlying member method code with example usage: obj.__call__(wr, _finalizer_registry, sub_debug, getpid) and returns: res