本文整理汇总了Python中IPython.zmq.ipkernel.IPKernelApp类的典型用法代码示例。如果您正苦于以下问题:Python IPKernelApp类的具体用法?Python IPKernelApp怎么用?Python IPKernelApp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPKernelApp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InternalIPKernel
class InternalIPKernel(object):
"""Class for managing an IPython kernel inside of QGIS.
IPython normally runs kernels in seperate processes, but this setup is
limiting in the case of QGIS because external kernels cannot access the
data and variables that QGIS is working with. This class manages an
in-process kernel and is capable of launching external consoles that can
attach to the kernel.
IPython Consoles are run as external processes because they rely on
Version 2 of the PyQt api and QGIS is using Version 1 which is
incompatible.
"""
def __init__(self):
self.ipkernel = IPKernelApp()
self.ipkernel.initialize(['python',
# Ensure the Kernel pre-loads the same modules as are available
# from the QGIS python console.
"--c='from qgis.core import *;import qgis.utils;'"])
# Ensure we use an event loop that is QGIS-friendly.
self.ipkernel.kernel.eventloop = loop_qgis
self.ipkernel.start()
# To create and track active qt consoles
self._qtconsole_cmd = ['ipython', 'qtconsole', '--existing'] + \
[os.path.basename(self.ipkernel.connection_file)]
self.consoles = []
def new_qt_console(self, evt=None):
self.consoles.append(subprocess.Popen(self._qtconsole_cmd))
def cleanup_consoles(self, evt=None):
for c in self.consoles:
c.kill()
示例2: pylab_kernel
def pylab_kernel(gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
kernel = IPKernelApp()
kernel.initialize(['python', '--pylab=%s' % gui,
#'--log-level=10'
])
return kernel
示例3: pylab_kernel
def pylab_kernel(gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
kernel = IPKernelApp()
# FIXME: we're hardcoding the heartbeat port b/c of a bug in IPython 0.11
# that will set it to 0 if not specified. Once this is fixed, the --hb
# parameter can be omitted and all ports will be automatic
kernel.initialize(['python', '--pylab=%s' % gui, '--hb=19999',
#'--log-level=10'
])
return kernel
示例4: get_connection_file
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])
示例5: pylab_kernel
def pylab_kernel(self,gui):
'''Launch an IPython kernel with pylab support for the gui.'''
log_debug,pdb,trace = False,True,False
tag = 'leoIPython.py:pylab_kernel'
kernel = IPKernelApp.instance()
# IPKernalApp is a singleton class.
# Return the singleton instance, creating it if necessary.
if kernel:
# pylab is needed for Qt event loop integration.
args = ['python','--pylab=%s' % (gui)]
if log_debug: args.append('--debug')
#'--log-level=10'
# '--pdb', # User-level debugging
try:
if pdb: g.pdb()
kernel.initialize(args)
# kernel objects: (Leo --ipython arg)
# kernel.session: zmq.session.Session
# kernel.shell: ZMQInteractiveShell
# kernel.shell.comm_manager: comm.manager.CommManager.
# kernel.shell.event = events.EventManager
# kernel.shell.run_cell (method)
# kernel.shell.hooks
except Exception:
sys.stdout = sys.__stdout__
print('%s: kernel.initialize failed!' % tag)
raise
else:
print('%s IPKernelApp.instance failed' % (tag))
return kernel
示例6: init_ipython
def init_ipython():
"""
Encapsulate Kernel creation logic: Only the kernel client, manager and shell are exposed
This is in order to ensure interoperability between major IPython changes
"""
if ipython_1:
manager = QtInProcessKernelManager()
manager.start_kernel()
manager.kernel.gui = 'qt4'
shell = manager.kernel.shell
shell.run_cell('%pylab inline')
client = manager.client()
client.start_channels()
else:
def event_loop(kernel):
kernel.timer = QTimer()
kernel.timer.timeout.connect(kernel.do_one_iteration)
kernel.timer.start(1000 * kernel._poll_interval)
kernel_app = IPKernelApp.instance()
kernel_app.initialize(['python', '--pylab=qt']) # at this point, print() won’t work anymore
kernel_app.kernel.eventloop = event_loop
connection_file = find_connection_file(kernel_app.connection_file)
manager = QtKernelManager(connection_file=connection_file)
manager.load_connection_file()
manager.start_channels()
kernel_app.start()
client = None
shell = kernel_app.shell
return client, manager, shell
示例7: bind_kernel
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")
示例8: __init__
def __init__(self):
self._app = IPKernelApp.instance()
self._app.initialize()
fh = logging.FileHandler(self.__class__.__name__ + ".log")
fh.setLevel(logging.DEBUG)
log = self._app.kernel.log
log.setLevel(logging.DEBUG)
log.addHandler(fh)
log.debug("kernel init")
示例9: pylab_kernel
def pylab_kernel(gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
kernel = IPKernelApp.instance()
# pylab is really needed, for Qt event loop integration
kernel.initialize(['python', '--pylab=%s' % gui,
#'--log-level=10'
])
return kernel
示例10: pylab_kernel
def pylab_kernel(gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
kernel = IPKernelApp.instance()
# Note: pylab command seems to be needed for event loop to behave nicely
kernel.initialize([get_executable(), '--pylab=%s' % gui,
"--c='%run -m mantidplotrc'"])
return kernel
示例11: fork_kernel
def fork_kernel(self, config, pipe, resource_limits, logfile):
os.setpgrp()
logging.basicConfig(filename=self.filename,format=str(uuid.uuid4()).split('-')[0]+': %(asctime)s %(message)s',level=logging.DEBUG)
ka = IPKernelApp.instance(config=config, ip=config["ip"])
ka.initialize([])
if self.update_function is not None:
self.update_function(ka)
for r, limit in resource_limits.iteritems():
resource.setrlimit(getattr(resource, r), (limit, limit))
pipe.send({"ip": ka.ip, "key": ka.session.key, "shell_port": ka.shell_port,
"stdin_port": ka.stdin_port, "hb_port": ka.hb_port, "iopub_port": ka.iopub_port})
pipe.close()
ka.start()
示例12: __init__
def __init__(self):
self.ipkernel = IPKernelApp()
self.ipkernel.initialize(['python',
# Ensure the Kernel pre-loads the same modules as are available
# from the QGIS python console.
"--c='from qgis.core import *;import qgis.utils;'"])
# Ensure we use an event loop that is QGIS-friendly.
self.ipkernel.kernel.eventloop = loop_qgis
self.ipkernel.start()
# To create and track active qt consoles
self._qtconsole_cmd = ['ipython', 'qtconsole', '--existing'] + \
[os.path.basename(self.ipkernel.connection_file)]
self.consoles = []
示例13: fork_kernel
def fork_kernel(self, sage_dict, config, q):
ka = IPKernelApp.instance(config=config)
ka.initialize([])
ka.kernel.shell.user_ns.update(sage_dict)
ka.kernel.shell.user_ns.update(interact.classes)
if "sys" in ka.kernel.shell.user_ns:
ka.kernel.shell.user_ns["sys"]._interacts = interact.interacts
else:
sys._interacts = interact.interacts
ka.kernel.shell.user_ns["sys"] = sys
ka.kernel.shell.user_ns["interact"] = interact.interact_func(ka.session, ka.iopub_socket)
q.send({"ip": ka.ip, "key": ka.session.key, "shell_port": ka.shell_port,
"stdin_port": ka.stdin_port, "hb_port": ka.hb_port, "iopub_port": ka.iopub_port})
q.close()
ka.start()
示例14: pylab_kernel
def pylab_kernel(self,gui):
"""Launch and return an IPython kernel with pylab support for the desired gui
"""
trace = True
tag = 'leoIPython.py'
kernel = IPKernelApp.instance()
if kernel:
# pylab is really needed, for Qt event loop integration.
try:
kernel.initialize(['python','--pylab=%s' % (gui)])
#'--log-level=10'
if trace: print('%s: kernel: %s' % (tag,kernel))
except Exception:
print('%s: kernel.initialize failed!' % tag)
raise
else:
print('%s IPKernelApp.instance failed' % (tag))
return kernel
示例15: __init__
def __init__(self, gui, shell):
self.shell = shell
self.logger = None
if shell is None:
# Start IPython kernel with GUI event loop support
self.ipkernel = IPKernelApp.instance()
self.ipkernel.initialize(['python', '--gui=%s' % gui,
#'--log-level=10' # for debugging
])
# This application will also act on the shell user namespace
self.namespace = self.ipkernel.shell.user_ns
else:
self.ipkernel = shell.config.IPKernelApp
self.namespace = shell.user_ns
# To create and track active qt consoles
self.consoles = []