docstr: Embeds IPython into a running python program.
  
  Parameters
  ----------
  
  local_ns, module
    Working local namespace (a dict) and module (a module or similar
    object). If given as None, they are automatically taken from the scope
    where the shell was called, so that program variables become visible.
  
  stack_depth : int
    How many levels in the stack to go to looking for namespaces (when
    local_ns or module is None). This allows an intermediate caller to
    make sure that this function gets the namespace from the intended
    level in the stack. By default (0) it will get its locals and globals
    from the immediate caller.
  
  compile_flags
    A bit field identifying the __future__ features
    that are enabled, as passed to the builtin :func:`compile` function.
    If given as None, they are automatically taken from the scope where
    the shell was called.
docstr_tok: ["Embeds","IPython","into","a","running","python","program",".","Parameters","--","--","--","--","--","local_ns",",","module","Working","local","namespace","(","a","dict",")","and","module","(","a","module","or","similar","object",")",".","If","given","as","None",",","they","are","automatically","taken","from","the","scope","where","the","shell","was","called",",","so","that","program","variables","become","visible",".","stack_depth",":","int","How","many","levels","in","the","stack","to","go","to","looking","for","namespaces","(","when","local_ns","or","module","is","None",")",".","This","allows","an","intermediate","caller","to","make","sure","that","this","function","gets","the","namespace","from","the","intended","level","in","the","stack",".","By","default","(","0",")","it","will","get","its","locals","and","globals","from","the","immediate","caller",".","compile_flags","A","bit","field","identifying","the","__future__","features","that","are","enabled",",","as","passed","to","the","builtin",":","func",":","`","compile","`","function",".","If","given","as","None",",","they","are","automatically","taken","from","the","scope","where","the","shell","was","called","."]
code: def mainloop(
      self,
      local_ns=None,
      module=None,
      stack_depth=0,
      display_banner=None,
      global_ns=None,
      compile_flags=None,
  ):
      """Embeds IPython into a running python program.
  
      Parameters
      ----------
  
      local_ns, module
        Working local namespace (a dict) and module (a module or similar
        object). If given as None, they are automatically taken from the scope
        where the shell was called, so that program variables become visible.
  
      stack_depth : int
        How many levels in the stack to go to looking for namespaces (when
        local_ns or module is None). This allows an intermediate caller to
        make sure that this function gets the namespace from the intended
        level in the stack. By default (0) it will get its locals and globals
        from the immediate caller.
  
      compile_flags
        A bit field identifying the __future__ features
        that are enabled, as passed to the builtin :func:`compile` function.
        If given as None, they are automatically taken from the scope where
        the shell was called.
  
      """
  
      if (global_ns is not None) and (module is None):
          raise DeprecationWarning(
              "'global_ns' keyword argument is deprecated, and has been removed in IPython 5.0 use `module` keyword argument instead."
          )
  
      if display_banner is not None:
          warnings.warn(
              "The display_banner parameter is deprecated since IPython 4.0",
              DeprecationWarning,
          )
  
      # Get locals and globals from caller
      if (
          local_ns is None or module is None or compile_flags is None
      ) and self.default_user_namespaces:
          call_frame = sys._getframe(stack_depth).f_back
  
          if local_ns is None:
              local_ns = call_frame.f_locals
          if module is None:
              global_ns = call_frame.f_globals
              try:
                  module = sys.modules[global_ns["__name__"]]
              except KeyError:
                  warnings.warn(
                      "Failed to get module %s"
                      % global_ns.get("__name__", "unknown module")
                  )
                  module = DummyMod()
                  module.__dict__ = global_ns
          if compile_flags is None:
              compile_flags = (
                  call_frame.f_code.co_flags & compilerop.PyCF_MASK
              )
  
      # Save original namespace and module so we can restore them after
      # embedding; otherwise the shell doesn't shut down correctly.
      orig_user_module = self.user_module
      orig_user_ns = self.user_ns
      orig_compile_flags = self.compile.flags
  
      # Update namespaces and fire up interpreter
  
      # The global one is easy, we can just throw it in
      if module is not None:
          self.user_module = module
  
      # But the user/local one is tricky: ipython needs it to store internal
      # data, but we also need the locals. We'll throw our hidden variables
      # like _ih and get_ipython() into the local namespace, but delete them
      # later.
      if local_ns is not None:
          reentrant_local_ns = {
              k: v
              for (k, v) in local_ns.items()
              if k not in self.user_ns_hidden.keys()
          }
          self.user_ns = reentrant_local_ns
          self.init_user_ns()
  
      # Compiler flags
      if compile_flags is not None:
          self.compile.flags = compile_flags
  
      # make sure the tab-completer has the correct frame information, so it
      # actually completes using the frame's locals/globals
      self.set_completer_frame()
  
      with self.builtin_trap, self.display_trap:
          self.interact()
  
      # now, purge out the local namespace of IPython's hidden variables.
      if local_ns is not None:
          local_ns.update(
              {
                  k: v
                  for (k, v) in self.user_ns.items()
                  if k not in self.user_ns_hidden.keys()
              }
          )
  
      # Restore original namespace so shell can shut down when we exit.
      self.user_module = orig_user_module
      self.user_ns = orig_user_ns
      self.compile.flags = orig_compile_flags
  
imports: from __future__ import with_statement
  from __future__ import print_function
  import sys
  import warnings
  from IPython.core import ultratb, compilerop
  from IPython.core import magic_arguments
  from IPython.core.magic import Magics, magics_class, line_magic
  from IPython.core.interactiveshell import DummyMod, InteractiveShell
  from IPython.terminal.interactiveshell import TerminalInteractiveShell
  from IPython.terminal.ipapp import load_default_config
  from traitlets import Bool, CBool, Unicode
  from IPython.utils.io import ask_yes_no
label_desc: Use image node_id 8 for calling the InteractiveShellEmbed obj's underlying member method code with example usage: obj.mainloop(local_ns, module, stack_depth, display_banner, global_ns, compile_flags) without return types