本文整理汇总了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]