本文整理汇总了Python中ipykernel.kernelapp.IPKernelApp.initialized方法的典型用法代码示例。如果您正苦于以下问题:Python IPKernelApp.initialized方法的具体用法?Python IPKernelApp.initialized怎么用?Python IPKernelApp.initialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipykernel.kernelapp.IPKernelApp
的用法示例。
在下文中一共展示了IPKernelApp.initialized方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_one_iteration
# 需要导入模块: from ipykernel.kernelapp import IPKernelApp [as 别名]
# 或者: from ipykernel.kernelapp.IPKernelApp import initialized [as 别名]
def do_one_iteration():
"""Perform an iteration on IPython kernel runloop"""
if IPKernelApp.initialized():
app = IPKernelApp.instance()
app.kernel.do_one_iteration()
else:
raise Exception("Kernel is not initialized")
示例2: bind_kernel
# 需要导入模块: from ipykernel.kernelapp import IPKernelApp [as 别名]
# 或者: from ipykernel.kernelapp.IPKernelApp import initialized [as 别名]
def bind_kernel(**kwargs):
"""Bind an Engine's Kernel to be used as a full IPython kernel.
This allows a running Engine to be used simultaneously as a full IPython kernel
with the QtConsole or other frontends.
This function returns immediately.
"""
from ipykernel.kernelapp import IPKernelApp
from ipyparallel.apps.ipengineapp import IPEngineApp
# first check for IPKernelApp, in which case this should be a no-op
# because there is already a bound kernel
if IPKernelApp.initialized() and isinstance(IPKernelApp._instance, IPKernelApp):
return
if IPEngineApp.initialized():
try:
app = IPEngineApp.instance()
except MultipleInstanceError:
pass
else:
return app.bind_kernel(**kwargs)
raise RuntimeError("bind_kernel be called from an IPEngineApp instance")
示例3: get_connection_file
# 需要导入模块: from ipykernel.kernelapp import IPKernelApp [as 别名]
# 或者: from ipykernel.kernelapp.IPKernelApp import initialized [as 别名]
def get_connection_file(app=None):
"""Return the path to the connection file of an app
Parameters
----------
app : IPKernelApp instance [optional]
If unspecified, the currently running app will be used
"""
if app is None:
from ipykernel.kernelapp import IPKernelApp
if not IPKernelApp.initialized():
raise RuntimeError("app not specified, and not in a running Kernel")
app = IPKernelApp.instance()
return filefind(app.connection_file, ['.', app.connection_dir])
示例4: embed_kernel
# 需要导入模块: from ipykernel.kernelapp import IPKernelApp [as 别名]
# 或者: from ipykernel.kernelapp.IPKernelApp import initialized [as 别名]
def embed_kernel(module=None, local_ns=None, **kwargs):
"""Embed and start an IPython kernel in a given scope.
Parameters
----------
module : ModuleType, optional
The module to load into IPython globals (default: caller)
local_ns : dict, optional
The namespace to load into IPython user namespace (default: caller)
kwargs : various, optional
Further keyword args are relayed to the IPKernelApp constructor,
allowing configuration of the Kernel. Will only have an effect
on the first embed_kernel call for a given process.
"""
# get the app if it exists, or set it up if it doesn't
if IPKernelApp.initialized():
app = IPKernelApp.instance()
else:
app = IPKernelApp.instance(**kwargs)
app.initialize(sys.argv)
# Undo unnecessary sys module mangling from init_sys_modules.
# This would not be necessary if we could prevent it
# in the first place by using a different InteractiveShell
# subclass, as in the regular embed case.
main = app.kernel.shell._orig_sys_modules_main_mod
if main is not None:
sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main
# load the calling scope if not given
(caller_module, caller_locals) = extract_module_locals(1)
if module is None:
module = caller_module
if local_ns is None:
local_ns = caller_locals
app.kernel.user_module = None
app.kernel.user_ns = None
app.shell.set_completer_frame()
if app.poller is not None:
app.poller.start()
app.kernel.start()
return app
示例5: start
# 需要导入模块: from ipykernel.kernelapp import IPKernelApp [as 别名]
# 或者: from ipykernel.kernelapp.IPKernelApp import initialized [as 别名]
def start(self):
if self._timer is not None:
raise Exception("IPython kernel is already running.")
# The IPKernelApp initialization is based on the IPython source for
# IPython.embed_kernel available here:
# https://github.com/ipython/ipython/blob/rel-3.2.1/IPython/kernel/zmq/embed.py
if IPKernelApp.initialized():
app = IPKernelApp.instance()
else:
app = IPKernelApp.instance(
outstream_class='ipyida.kernel.IDATeeOutStream'
)
app.initialize()
main = app.kernel.shell._orig_sys_modules_main_mod
if main is not None:
sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main
# IPython <= 3.2.x will send exception to sys.__stderr__ instead of
# sys.stderr. IDA's console will not be able to display exceptions if we
# don't send it to IDA's sys.stderr. To fix this, we call both the
# ipython's and IDA's excepthook (IDA's excepthook is actually Python's
# default).
sys.excepthook = wrap_excepthook(sys.excepthook)
app.shell.set_completer_frame()
app.kernel.start()
app.kernel.do_one_iteration()
self.connection_file = app.connection_file
def ipython_kernel_iteration():
app.kernel.do_one_iteration()
return int(1000 * app.kernel._poll_interval)
self._timer = idaapi.register_timer(int(1000 * app.kernel._poll_interval), ipython_kernel_iteration)
示例6: in_notebook
# 需要导入模块: from ipykernel.kernelapp import IPKernelApp [as 别名]
# 或者: from ipykernel.kernelapp.IPKernelApp import initialized [as 别名]
def in_notebook(): return IPKernelApp.initialized()
def in_ipynb():