本文整理汇总了Python中IPython.zmq.ipkernel.IPKernelApp.initialized方法的典型用法代码示例。如果您正苦于以下问题:Python IPKernelApp.initialized方法的具体用法?Python IPKernelApp.initialized怎么用?Python IPKernelApp.initialized使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.zmq.ipkernel.IPKernelApp
的用法示例。
在下文中一共展示了IPKernelApp.initialized方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bind_kernel
# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.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 IPython.zmq.ipkernel import IPKernelApp
from IPython.parallel.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")
示例2: get_connection_file
# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import initialized [as 别名]
def get_connection_file(app=None):
"""Return the path to the connection file of an app
Parameters
----------
app : KernelApp instance [optional]
If unspecified, the currently running app will be used
"""
if app is None:
from IPython.zmq.ipkernel 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.profile_dir.security_dir])
示例3: _start_kernel
# 需要导入模块: from IPython.zmq.ipkernel import IPKernelApp [as 别名]
# 或者: from IPython.zmq.ipkernel.IPKernelApp import initialized [as 别名]
def _start_kernel():
"""starts the ipython kernel and returns the ipython app"""
from IPython.zmq.ipkernel import IPKernelApp
from zmq.eventloop import ioloop
global _kernel_running, _ipython_app
if _kernel_running:
return _ipython_app
# get the app if it exists, or set it up if it doesn't
if IPKernelApp.initialized():
app = IPKernelApp.instance()
else:
app = IPKernelApp.instance()
app.initialize()
# 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
app.kernel.user_module = sys.modules[__name__]
app.kernel.user_ns = {}
# patch in auto-completion support
# added in https://github.com/ipython/ipython/commit/f4be28f06c2b23cd8e4a3653b9e84bde593e4c86
# we effectively make the same patches via monkeypatching
from IPython.core.interactiveshell import InteractiveShell
old_set_completer_frame = InteractiveShell.set_completer_frame
# restore old set_completer_frame that gets no-op'd out in ZmqInteractiveShell.__init__
bound_scf = old_set_completer_frame.__get__(app.shell, InteractiveShell)
app.shell.set_completer_frame = bound_scf
app.shell.set_completer_frame()
# start the kernel
app.kernel.start()
# set up a timer to periodically poll the zmq ioloop
loop = ioloop.IOLoop.instance()
def poll_ioloop(timer_id, time):
global _kernel_running
# if the kernel has been closed then run the event loop until it gets to the
# stop event added by IPKernelApp.shutdown_request
if app.kernel.shell.exit_now:
_log.debug("IPython kernel stopping (%s)" % app.connection_file)
timer.kill_timer(timer_id)
ioloop.IOLoop.instance().start()
_kernel_running = False
return
# otherwise call the event loop but stop immediately if there are no pending events
loop.add_timeout(0, lambda: loop.add_callback(loop.stop))
ioloop.IOLoop.instance().start()
_log.debug("IPython kernel starting. Use '--existing %s' to connect." % app.connection_file)
timer.set_timer(100, poll_ioloop)
_kernel_running = True
_ipython_app = app
return _ipython_app