本文整理汇总了Python中ipykernel.kernelbase.Kernel.initialized方法的典型用法代码示例。如果您正苦于以下问题:Python Kernel.initialized方法的具体用法?Python Kernel.initialized怎么用?Python Kernel.initialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipykernel.kernelbase.Kernel
的用法示例。
在下文中一共展示了Kernel.initialized方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: from ipykernel.kernelbase import Kernel [as 别名]
# 或者: from ipykernel.kernelbase.Kernel import initialized [as 别名]
def apply(self, expr, args, evaluation):
'Manipulate[expr_, args__]'
if (not _jupyter) or (not Kernel.initialized()) or (Kernel.instance() is None):
return evaluation.message('Manipulate', 'jupyter')
instantiator = _WidgetInstantiator() # knows about the arguments and their widgets
for arg in args.get_sequence():
try:
if not instantiator.add(arg, evaluation): # not a valid argument pattern?
return
except IllegalWidgetArguments as e:
return evaluation.message('Manipulate', 'widgetargs', strip_context(str(e.var)))
except JupyterWidgetError as e:
return evaluation.message('Manipulate', 'widgetmake', e.err)
clear_output_callback = evaluation.output.clear
display_data_callback = evaluation.output.display # for pushing updates
try:
clear_output_callback(wait=True)
except NotImplementedError:
return evaluation.message('Manipulate', 'imathics')
def callback(**kwargs):
clear_output_callback(wait=True)
line_no = evaluation.definitions.get_line_no()
vars = [Expression('Set', Symbol(name), value) for name, value in kwargs.items()]
evaluatable = Expression('ReleaseHold', Expression('Module', Expression('List', *vars), expr))
result = evaluation.evaluate(evaluatable, timeout=settings.TIMEOUT)
if result:
display_data_callback(data=result.result, metadata={})
evaluation.definitions.set_line_no(line_no) # do not increment line_no for manipulate computations
widgets = instantiator.get_widgets()
if len(widgets) > 0:
box = _interactive(instantiator.build_callback(callback), widgets) # create the widget
formatter = IPythonDisplayFormatter()
if not formatter(box): # make the widget appear on the Jupyter notebook
return evaluation.message('Manipulate', 'widgetdisp')
return Symbol('Null') # the interactive output is pushed via kernel.display_data_callback (see above)
示例2: _default_kernel
# 需要导入模块: from ipykernel.kernelbase import Kernel [as 别名]
# 或者: from ipykernel.kernelbase.Kernel import initialized [as 别名]
def _default_kernel(self):
if Kernel.initialized():
return Kernel.instance()