當前位置: 首頁>>代碼示例>>Python>>正文


Python NotebookNode.get方法代碼示例

本文整理匯總了Python中IPython.nbformat.current.NotebookNode.get方法的典型用法代碼示例。如果您正苦於以下問題:Python NotebookNode.get方法的具體用法?Python NotebookNode.get怎麽用?Python NotebookNode.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在IPython.nbformat.current.NotebookNode的用法示例。


在下文中一共展示了NotebookNode.get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: poll_for_msgs

# 需要導入模塊: from IPython.nbformat.current import NotebookNode [as 別名]
# 或者: from IPython.nbformat.current.NotebookNode import get [as 別名]
    def poll_for_msgs(self):
        """Polls for messages from the kernel.
        Used after submitting code for execution"""
        try:
            msg = self.iopub.get_msg(timeout=1)
            if msg['msg_type'] == 'status' and msg['content']['execution_state'] == 'idle':
                if _debugging: logging.info('Message -- {}:{}'.format(msg['msg_type'], msg['content']))
                self._previous_status = 'IDLE'
                return NotebookNode(output_type = 'IDLE')
        except Empty: # state should return to idle before queue becomes empty, but we ignore it now
            prevstat, self._previous_status = self._previous_status, 'EMPTY'
            retstat = 'END_CELL' if prevstat == 'IDLE' else 'EMPTY'
            # Assuming IDLE followed by EMPTY is the end-of-cell 
            return NotebookNode(output_type = retstat)

        self._previous_status = ''  # Not idle, that's all we are concerned about for now
        content, msg_type = msg['content'], msg['msg_type']

        if msg_type in ['status', 'pyin']: return NotebookNode(output_type = 'NoOp')

        out = NotebookNode(output_type = msg_type)
        if msg_type in ('display_data', 'pyout'):
            for mime, data in content['data'].items():
                try:
                    attr = self.MIME_MAP[mime]
                    tmpval =  RClansiconv(data) if attr == 'text' else data
                    setattr(out, attr, tmpval)
                except KeyError:
                    raise NotImplementedError('unhandled mime type: %s' % mime)
        elif msg_type == 'stream':
            setattr(out, 'text', RClansiconv(content['data']))
        elif msg_type == 'pyerr':
            setattr(out, 'html', RClansiconv('\n'.join(content['traceback']) + '\n'))
        else:
            if _debugging: logging.info('Unsupported: ' + msg_type)
            raise NotImplementedError('unhandled iopub message: %s' % msg_type)
        if _debugging: logging.info('Sending: msg_type: [{}]; HTML: [{}]; TEXT: [{}]'.format(msg_type, out.get('html', ''), out.get('text', '') ))
        return out # upstream process will handle it [e.g. send as an oob message]
開發者ID:FelipeJColon,項目名稱:rcloud,代碼行數:40,代碼來源:notebook_runner.py


注:本文中的IPython.nbformat.current.NotebookNode.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。