code: def start_ipython():
      """Start a global IPython shell, which we need for IPython-specific syntax."""
      global get_ipython
  
      # This function should only ever run once!
      if hasattr(start_ipython, "already_called"):
          return
      start_ipython.already_called = True
  
      # Store certain global objects that IPython modifies
      _displayhook = sys.displayhook
      _excepthook = sys.excepthook
      _main = sys.modules.get("__main__")
  
      # Create custom argv and namespaces for our IPython to be test-friendly
      config = tools.default_config()
      config.TerminalInteractiveShell.simple_prompt = True
  
      # Create and initialize our test-friendly IPython instance.
      shell = TerminalInteractiveShell.instance(
          config=config,
      )
  
      # A few more tweaks needed for playing nicely with doctests...
  
      # remove history file
      shell.tempfiles.append(config.HistoryManager.hist_file)
  
      # These traps are normally only active for interactive use, set them
      # permanently since we'll be mocking interactive sessions.
      shell.builtin_trap.activate()
  
      # Modify the IPython system call with one that uses getoutput, so that we
      # can capture subcommands and print them to Python's stdout, otherwise the
      # doctest machinery would miss them.
      shell.system = py3compat.MethodType(xsys, shell)
  
      shell._showtraceback = py3compat.MethodType(_showtraceback, shell)
  
      # IPython is ready, now clean up some global state...
  
      # Deactivate the various python system hooks added by ipython for
      # interactive convenience so we don't confuse the doctest system
      sys.modules["__main__"] = _main
      sys.displayhook = _displayhook
      sys.excepthook = _excepthook
  
      # So that ipython magics and aliases can be doctested (they work by making
      # a call into a global _ip object).  Also make the top-level get_ipython
      # now return this without recursively calling here again.
      _ip = shell
      get_ipython = _ip.get_ipython
      builtin_mod._ip = _ip
      builtin_mod.get_ipython = get_ipython
  
      # Override paging, so we don't require user interaction during the tests.
      def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
          if isinstance(strng, dict):
              strng = strng.get("text/plain", "")
          print(strng)
  
      page.orig_page = page.pager_page
      page.pager_page = nopage
  
      return _ip
  
file_path: catboost/contrib/python/ipython/py2/IPython/testing/globalipapp.py
imports: from __future__ import absolute_import
  from __future__ import print_function
  import sys
  import warnings
  from .None import tools
  from IPython.core import page
  from IPython.utils import io
  from IPython.utils import py3compat
  from IPython.utils.py3compat import builtin_mod
  from IPython.terminal.interactiveshell import TerminalInteractiveShell
label_desc: Use image node_id 4 for calling a global function with example usage: start_ipython() and returns: _ip