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


Python blocking.BlockingInProcessKernelClient类代码示例

本文整理汇总了Python中IPython.kernel.inprocess.blocking.BlockingInProcessKernelClient的典型用法代码示例。如果您正苦于以下问题:Python BlockingInProcessKernelClient类的具体用法?Python BlockingInProcessKernelClient怎么用?Python BlockingInProcessKernelClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BlockingInProcessKernelClient类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_interface

    def test_interface(self):
        """ Does the in-process kernel manager implement the basic KM interface?
        """
        km = InProcessKernelManager()
        self.assert_(not km.has_kernel)

        km.start_kernel()
        self.assert_(km.has_kernel)
        self.assert_(km.kernel is not None)

        kc = BlockingInProcessKernelClient(kernel=km.kernel)
        self.assert_(not kc.channels_running)

        kc.start_channels()
        self.assert_(kc.channels_running)

        old_kernel = km.kernel
        km.restart_kernel()
        self.assertIsNotNone(km.kernel)
        self.assertNotEquals(km.kernel, old_kernel)

        km.shutdown_kernel()
        self.assert_(not km.has_kernel)

        self.assertRaises(NotImplementedError, km.interrupt_kernel)
        self.assertRaises(NotImplementedError, km.signal_kernel, 9)

        kc.stop_channels()
        self.assert_(not kc.channels_running)
开发者ID:JohnGriffiths,项目名称:ipython,代码行数:29,代码来源:test_kernelmanager.py

示例2: test_execute

 def test_execute(self):
     """ Does executing code in an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.execute('foo = 1')
     self.assertEquals(km.kernel.shell.user_ns['foo'], 1)
开发者ID:AJRenold,项目名称:ipython,代码行数:9,代码来源:test_kernelmanager.py

示例3: get_kernel_pointer

def get_kernel_pointer(buffer):
    lisp.message("getting kernel for " + buffer)
    if buffer not in kernels:
        lisp.message("creating new " + buffer)
        km = InProcessKernelManager()
        km.start_kernel()
        kc = BlockingInProcessKernelClient(kernel=km.kernel)
        kc.start_channels()
        kernel = InProcessKernel()
        kernels[buffer] = (kc,kernel,kernel.shell.get_ipython())
        # run this so that plt, np pointers are ready
        kc.shell_channel.execute('%pylab inline')
    return kernels[buffer]
开发者ID:SemanticPrincess,项目名称:kod,代码行数:13,代码来源:pytexipy-notebook.py

示例4: test_stdout

    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, "foo\n")

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        out, err = assemble_output(kc.iopub_channel)
        self.assertEqual(out, "bar\n")
开发者ID:Tasarinan,项目名称:PortablePython3,代码行数:14,代码来源:test_kernel.py

示例5: test_stdout

    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, 'foo\n')

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        msg = get_stream_message(kc)
        self.assertEqual(msg['content']['text'], 'bar\n')
开发者ID:asudipta,项目名称:ipython,代码行数:14,代码来源:test_kernel.py

示例6: test_history

 def test_history(self):
     """ Does requesting history from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.wait_for_ready()
     kc.execute('%who')
     kc.history(hist_access_type='tail', n=1)
     msg = kc.shell_channel.get_msgs()[-1]
     self.assertEquals(msg['header']['msg_type'], 'history_reply')
     history = msg['content']['history']
     self.assertEquals(len(history), 1)
     self.assertEquals(history[0][2], '%who')
开发者ID:JohnGriffiths,项目名称:ipython,代码行数:15,代码来源:test_kernelmanager.py

示例7: test_complete

 def test_complete(self):
     """ Does requesting completion from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.wait_for_ready()
     km.kernel.shell.push({'my_bar': 0, 'my_baz': 1})
     kc.complete('my_ba', 5)
     msg = kc.get_shell_msg()
     self.assertEqual(msg['header']['msg_type'], 'complete_reply')
     self.assertEqual(sorted(msg['content']['matches']),
                       ['my_bar', 'my_baz'])
开发者ID:JohnGriffiths,项目名称:ipython,代码行数:14,代码来源:test_kernelmanager.py

示例8: test_inspect

 def test_inspect(self):
     """ Does requesting object information from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.wait_for_ready()
     km.kernel.shell.user_ns['foo'] = 1
     kc.inspect('foo')
     msg = kc.get_shell_msg()
     self.assertEqual(msg['header']['msg_type'], 'inspect_reply')
     content = msg['content']
     assert content['found']
     text = content['data']['text/plain']
     self.assertIn('int', text)
开发者ID:JohnGriffiths,项目名称:ipython,代码行数:16,代码来源:test_kernelmanager.py

示例9: InProcessKernelTestCase

class InProcessKernelTestCase(unittest.TestCase):

    def setUp(self):
        self.km = InProcessKernelManager()
        self.km.start_kernel()
        self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
        self.kc.start_channels()
        self.kc.wait_for_ready()

    @skipif_not_matplotlib
    def test_pylab(self):
        """Does %pylab work in the in-process kernel?"""
        kc = self.kc
        kc.execute('%pylab')
        out, err = assemble_output(kc.iopub_channel)
        self.assertIn('matplotlib', out)

    def test_raw_input(self):
        """ Does the in-process kernel handle raw_input correctly?
        """
        io = StringIO('foobar\n')
        sys_stdin = sys.stdin
        sys.stdin = io
        try:
            if py3compat.PY3:
                self.kc.execute('x = input()')
            else:
                self.kc.execute('x = raw_input()')
        finally:
            sys.stdin = sys_stdin
        self.assertEqual(self.km.kernel.shell.user_ns.get('x'), 'foobar')

    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, 'foo\n')

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        out, err = assemble_output(kc.iopub_channel)
        self.assertEqual(out, 'bar\n')
开发者ID:JohnGriffiths,项目名称:ipython,代码行数:46,代码来源:test_kernel.py

示例10: test_history

 def test_history(self):
     """ Does requesting history from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.execute("%who")
     kc.history(hist_access_type="tail", n=1)
     msg = kc.shell_channel.get_msgs()[-1]
     self.assertEquals(msg["header"]["msg_type"], "history_reply")
     history = msg["content"]["history"]
     self.assertEquals(len(history), 1)
     self.assertEquals(history[0][2], "%who")
开发者ID:pyarnold,项目名称:ipython,代码行数:14,代码来源:test_kernelmanager.py

示例11: test_complete

 def test_complete(self):
     """ Does requesting completion from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     km.kernel.shell.push({"my_bar": 0, "my_baz": 1})
     kc.complete("my_ba", "my_ba", 5)
     msg = kc.get_shell_msg()
     self.assertEqual(msg["header"]["msg_type"], "complete_reply")
     self.assertEqual(sorted(msg["content"]["matches"]), ["my_bar", "my_baz"])
开发者ID:pyarnold,项目名称:ipython,代码行数:12,代码来源:test_kernelmanager.py

示例12: test_object_info

 def test_object_info(self):
     """ Does requesting object information from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     km.kernel.shell.user_ns['foo'] = 1
     kc.object_info('foo')
     msg = kc.get_shell_msg()
     self.assertEquals(msg['header']['msg_type'], 'object_info_reply')
     self.assertEquals(msg['content']['name'], 'foo')
     self.assertEquals(msg['content']['type_name'], 'int')
开发者ID:AJRenold,项目名称:ipython,代码行数:13,代码来源:test_kernelmanager.py

示例13: setUp

 def setUp(self):
     self.km = InProcessKernelManager()
     self.km.start_kernel()
     self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
     self.kc.start_channels()
     self.kc.wait_for_ready()
开发者ID:Tasarinan,项目名称:PortablePython3,代码行数:6,代码来源:test_kernel.py


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