本文整理汇总了Python中IPython.kernel.zmq.kernelapp.IPKernelApp.launch_instance方法的典型用法代码示例。如果您正苦于以下问题:Python IPKernelApp.launch_instance方法的具体用法?Python IPKernelApp.launch_instance怎么用?Python IPKernelApp.launch_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.kernel.zmq.kernelapp.IPKernelApp
的用法示例。
在下文中一共展示了IPKernelApp.launch_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
if not os.path.exists(self.hist_file):
with open(self.hist_file, 'wb') as f:
f.write('')
with open(self.hist_file, 'rb') as f:
history = f.readlines()
history = history[:self.max_hist_cache]
self.hist_cache = history
self.log.debug('**HISTORY:')
self.log.debug(history)
history = [(None, None, h) for h in history]
return {'history': history}
def do_shutdown(self, restart):
self.log.debug("**Shutting down")
self.idlwrapper.child.kill(signal.SIGKILL)
if self.hist_file:
with open(self.hist_file,'wb') as f:
data = '\n'.join(self.hist_cache[-self.max_hist_cache:])
f.write(data.encode('utf-8'))
return {'status':'ok', 'restart':restart}
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=IDLKernel)
示例2: get_variable
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
def get_variable(self, name):
"""
Get a variable from the kernel language.
"""
python_magic = self.line_magics['python']
return python_magic.env.get(name, None)
def do_execute_direct(self, code):
python_magic = self.line_magics['python']
return python_magic.eval(code.strip())
def do_function_direct(self, function_name, arg):
"""
Call a function in the kernel language with args (as a single item).
"""
python_magic = self.line_magics['python']
return python_magic.eval("%s(%s)" % (function_name, arg))
def get_completions(self, info):
python_magic = self.line_magics['python']
return python_magic.get_completions(info)
def get_kernel_help_on(self, info, level=0, none_on_fail=False):
python_magic = self.line_magics['python']
return python_magic.get_help_on(info, level, none_on_fail)
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=MetaKernelPython)
示例3: do_shutdown
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
):
self.continuation = False
self.ignore_output()
code = self.remove_continuations(code.strip())
mata_magic = re.match(r'\s*%%mata\s+', code)
if mata_magic:
code = 'mata\n' + code[mata_magic.end():] + '\nend\n'
try:
self.stata_do(' ' + code + '\n')
self.respond()
except KeyboardInterrupt:
self.stata.UtilSetStataBreak()
self.respond()
return {'status': 'abort', 'execution_count': self.execution_count}
msg = {
'status': 'ok',
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {}
}
return msg
def do_shutdown(self, restart):
self.stata_do(' exit, clear\n')
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=StataKernel)
示例4: do_execute_direct
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
def do_execute_direct(self, code):
if not code.strip():
return
self.log.debug('execute: %s' % code)
shell_magic = self.line_magics['shell']
resp = shell_magic.eval(code.strip())
self.log.debug('execute done')
return resp.strip()
def get_completions(self, info):
shell_magic = self.line_magics['shell']
return shell_magic.get_completions(info)
def get_kernel_help_on(self, info, level=0, none_on_fail=False):
code = info['code'].strip()
if not code or len(code.split()) > 1:
if none_on_fail:
return None
else:
return ""
shell_magic = self.line_magics['shell']
return shell_magic.get_help_on(info, level, none_on_fail)
def repr(self, data):
return data
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=MetaKernelBash)
示例5:
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
'stream', {
'name': 'stdout',
'data': 'Richer print'})
# We prepare the response with our rich data
# (the plot).
content = {'source': 'kernel',
'data': {'text/html': out.data},
'metadata': {},
'text': [repr(out)]}
# We send the display_data message with the
# contents.
self.send_response(self.iopub_socket,
'display_data', content)
else:
stream_content = {'name': 'stdout', 'data': output}
self.send_response(self.iopub_socket,
'stream', stream_content)
# We return the exection results.
return {'status': 'ok',
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {}}
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=PrintKernel)
示例6: banner
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
def banner(self):
if self._banner is None:
self._banner = check_output(['bash', '--version']).decode('utf-8')
return self._banner
def makeWrapper(self):
"""Start a bash shell and return a :class:`REPLWrapper` object.
Note that this is equivalent :function:`metakernel.pyexpect.bash`,
but is used here as an example of how to be cross-platform.
"""
if os.name == 'nt':
prompt_regex = u('__repl_ready__')
prompt_emit_cmd = u('echo __repl_ready__')
prompt_change_cmd = None
else:
prompt_change_cmd = u("PS1='{0}' PS2='{1}' PROMPT_COMMAND=''")
prompt_emit_cmd = None
prompt_regex = re.compile('[$#]')
extra_init_cmd = "export PAGER=cat"
return REPLWrapper('bash', prompt_regex, prompt_change_cmd,
prompt_emit_cmd=prompt_emit_cmd,
extra_init_cmd=extra_init_cmd)
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=BashKernel)
示例7: isinstance
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
settings.setdefault('size', '560,420')
width, height = 560, 420
if isinstance(settings['size'], tuple):
width, height = settings['size']
elif settings['size']:
try:
width, height = settings['size'].split(',')
width, height = int(width), int(height)
except Exception as e:
self.Error(e)
size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s])\n;"
self.do_execute_direct(size % (width / 150., height / 150.))
def repr(self, obj):
return obj
def restart_kernel(self):
"""Restart the kernel"""
self._matlab.stop()
def do_shutdown(self, restart):
with open('test.txt', 'w') as fid:
fid.write('hey hey\n')
self._matlab.stop()
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=MatlabKernel)
示例8:
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
from .kernel import *
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=RedisKernel)
示例9:
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
from IPython.kernel.zmq.kernelapp import IPKernelApp
from .kernel import CalystoScheme
IPKernelApp.launch_instance(kernel_class=CalystoScheme)
示例10: get_usage
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
implementation_version = '1.0'
language = 'text'
language_version = '0.1'
banner = "MetaKernel Echo - as useful as a parrot"
language_info = {
'mimetype': 'text/plain',
'name': 'text',
# ------ If different from 'language':
# 'codemirror_mode': {
# "version": 2,
# "name": "ipython"
# }
# 'pygments_lexer': 'language',
# 'version' : "x.y.z",
'file_extension': '.txt',
'help_links': MetaKernel.help_links,
}
def get_usage(self):
return "This is the echo kernel."
def do_execute_direct(self, code):
return code.rstrip()
def repr(self, data):
return repr(data)
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=MetaKernelEcho)
示例11: isinstance
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
width, height = 560, 420
if isinstance(settings['size'], tuple):
width, height = settings['size']
elif settings['size']:
try:
width, height = settings['size'].split(',')
width, height = int(width), int(height)
except Exception as e:
self.Error('Error setting plot settings: %s' % e)
size = "set(0, 'defaultfigurepaperposition', [0 0 %s %s]);"
cmds.append(size % (width / 150., height / 150.))
self.do_execute_direct('\n'.join(cmds))
def _make_figs(self, plot_dir):
cmd = """
figHandles = get(0, 'children');
for fig=1:length(figHandles);
h = figHandles(fig);
filename = fullfile('%s', ['OctaveFig', sprintf('%%03d', fig)]);
saveas(h, [filename, '.%s']);
close(h);
end;
""" % (plot_dir, self._plot_fmt)
super(OctaveKernel, self).do_execute_direct(cmd.replace('\n', ''))
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=OctaveKernel)
示例12: BrainfuckKernel
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
class BrainfuckKernel(Kernel):
implementation = 'brainfuck'
implementation_version = '1.0'
language = 'brainfuck'
language_version = '0.1'
language_info = {'mimetype': 'text/plain', 'name': 'brainfuck'}
banner = "Brainfuck Kernel - it fucks with your brain"
def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
if not silent:
brainy = Brainy()
brainy.eval(code)
code_result = brainy.get_output()
stream_content = {'name': 'stdout', 'text': code_result}
self.send_response(self.iopub_socket, 'stream', stream_content)
return {'status': 'ok',
# The base class increments the execution count
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {},
}
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=BrainfuckKernel)
else:
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=BrainfuckKernel)
示例13:
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
from IPython.kernel.zmq.kernelapp import IPKernelApp
from .kernel import NielsKernel
IPKernelApp.launch_instance(kernel_class=NielsKernel)
示例14:
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
from IPython.kernel.zmq.kernelapp import IPKernelApp
from .kernel import SkulptPythonKernel
IPKernelApp.launch_instance(kernel_class=SkulptPythonKernel)
示例15: NodeKernel
# 需要导入模块: from IPython.kernel.zmq.kernelapp import IPKernelApp [as 别名]
# 或者: from IPython.kernel.zmq.kernelapp.IPKernelApp import launch_instance [as 别名]
from IPython.kernel.zmq.kernelbase import Kernel
class NodeKernel(Kernel):
implementation = "node-kernel"
implementation_version = "test"
language = "javascript"
language_version = "test"
banner = "test"
def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False):
if not silent:
stream_content = {'name': 'stdout', 'data':'hi!'}
self.send_response(self.iopub_socket, 'stream', stream_content)
return {'status': 'ok', 'execution_count': self.execution_count,
'payload': [], 'user_expressions': {}}
if __name__ == '__main__':
from IPython.kernel.zmq.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=NodeKernel)