当前位置: 首页>>代码示例>>Python>>正文


Python Kernel.initialized方法代码示例

本文整理汇总了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)
开发者ID:Piruzzolo,项目名称:Mathics,代码行数:48,代码来源:manipulate.py

示例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()
开发者ID:BarnetteME1,项目名称:DnD-stuff,代码行数:5,代码来源:comm.py


注:本文中的ipykernel.kernelbase.Kernel.initialized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。