'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.'

def mainloop(self, local_ns=None, module=None, stack_depth=0, display_banner=None, global_ns=None, compile_flags=None):

    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)
    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)
    orig_user_module = self.user_module
    orig_user_ns = self.user_ns
    orig_compile_flags = self.compile.flags
    if (module is not None):
        self.user_module = module
    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()
    if (compile_flags is not None):
        self.compile.flags = compile_flags
    self.set_completer_frame()
    with self.builtin_trap:
        with self.display_trap:
            self.interact()
    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())})
    self.user_module = orig_user_module
    self.user_ns = orig_user_ns
    self.compile.flags = orig_compile_flags
