當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。