MCPcopy Index your code
hub / github.com/ipython/ipython / embed_kernel

Function embed_kernel

IPython/__init__.py:74–115  ·  view source on GitHub ↗

Embed and start an IPython kernel in a given scope. If you don't want the kernel to initialize the namespace from the scope of the surrounding function, and/or you want to load full IPython configuration, you probably want `IPython.start_kernel()` instead. This is a deprecated

(module=None, local_ns=None, **kwargs)

Source from the content-addressed store, hash-verified

72
73
74def embed_kernel(module=None, local_ns=None, **kwargs):
75 """Embed and start an IPython kernel in a given scope.
76
77 If you don't want the kernel to initialize the namespace
78 from the scope of the surrounding function,
79 and/or you want to load full IPython configuration,
80 you probably want `IPython.start_kernel()` instead.
81
82 This is a deprecated alias for `ipykernel.embed.embed_kernel()`,
83 to be removed in the future.
84 You should import directly from `ipykernel.embed`; this wrapper
85 fails anyway if you don't have `ipykernel` package installed.
86
87 Parameters
88 ----------
89 module : types.ModuleType, optional
90 The module to load into IPython globals (default: caller)
91 local_ns : dict, optional
92 The namespace to load into IPython user namespace (default: caller)
93 **kwargs : various, optional
94 Further keyword args are relayed to the IPKernelApp constructor,
95 such as `config`, a traitlets :class:`Config` object (see :ref:`configure_start_ipython`),
96 allowing configuration of the kernel. Will only have an effect
97 on the first embed_kernel call for a given process.
98 """
99
100 warnings.warn(
101 "import embed_kernel from ipykernel.embed directly (since 2013)."
102 " Importing from IPython will be removed in the future",
103 DeprecationWarning,
104 stacklevel=2,
105 )
106
107 (caller_module, caller_locals) = extract_module_locals(1)
108 if module is None:
109 module = caller_module
110 if local_ns is None:
111 local_ns = dict(**caller_locals)
112
113 # Only import .zmq when we really need it
114 from ipykernel.embed import embed_kernel as real_embed_kernel
115 real_embed_kernel(module=module, local_ns=local_ns, **kwargs)
116
117def start_ipython(argv=None, **kwargs):
118 """Launch a normal IPython instance (as opposed to embedded)

Callers

nothing calls this directly

Calls 2

extract_module_localsFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…