code: def _find_function_from_code(frame, code):
      """
      Given a frame and a compiled function code, find the corresponding function object within the frame.
  
      This function addresses the following problem: when handling a stacktrace, we receive information about
      which piece of code was being executed in the form of a CodeType object. That objects contains function name,
      file name, line number, and the compiled bytecode. What it *doesn't* contain is the function object itself.
  
      So this utility function aims at locating this function object, and it does so by searching through objects
      in the preceding local frame (i.e. the frame where the function was called from). We expect that the function
      should usually exist there -- either by itself, or as a method on one of the objects.
  
      :param types.FrameType frame: local frame where the function ought to be found somewhere.
      :param types.CodeType code: the compiled code of the function to look for.
  
      :returns: the function object, or None if not found.
      """
  
      def find_code(iterable, depth=0):
          if depth > 3:
              return  # Avoid potential infinite loops, or generally objects that are too deep.
          for item in iterable:
              if item is None:
                  continue
              found = None
              if hasattr(item, "__code__") and (
                  (code.__eq__(item.__code__)) is True
              ):
                  found = item
              elif isinstance(item, type) or isinstance(
                  item, ModuleType
              ):  # class / module
                  try:
                      found = find_code(
                          (getattr(item, n, None) for n in dir(item)),
                          depth + 1,
                      )
                  except Exception:
                      # Sometimes merely getting module's attributes may cause an exception. For example :mod:`six.moves`
                      # is such an offender...
                      continue
              elif isinstance(item, (list, tuple, set)):
                  found = find_code(item, depth + 1)
              elif isinstance(item, dict):
                  found = find_code(item.values(), depth + 1)
              if found:
                  return found
  
      return find_code(frame.f_locals.values()) or find_code(
          frame.f_globals.values()
      )
  
file_path: h2o-3/h2o-py/h2o/utils/debugging.py
imports: import inspect
  import re
  import sys
  from types import ModuleType
  from h2o.exceptions import H2OJobCancelled, H2OSoftError
  from h2o.utils.compatibility import *
label_desc: Use image node_id 6 for calling a global function with example usage: _find_function_from_code(frame, code) and returns: unknown, found