Exemplo n.º 1
0
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]
Exemplo n.º 2
0
    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.shell_channel.execute('print("bar")')
        msg = get_stream_message(kc)
        self.assertEqual(msg['content']['text'], 'bar\n')
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
def main():
    app = guisupport.get_app_qt4()

    # Create a kernel. 
    #
    # Setting the GUI is not necessary for the normal operation of the kernel,
    # but it is used for IPython GUI's integration, particularly in pylab. By
    # default, the inline backend is used, which is safe under all toolkits.
    #
    # WARNING: Under no circumstances should another GUI toolkit, like wx, be
    # used when running a Qt application. This will lead to unexpected behavior,
    # including segfaults.
    kernel = InProcessKernel(gui='qt4')

    # Populate the kernel's namespace.
    kernel.shell.push({'x': 0, 'y': 1, 'z': 2})

    # Create a kernel manager for the frontend and register it with the kernel.
    km = QtInProcessKernelManager(kernel=kernel)
    km.start_channels()
    kernel.frontends.append(km)

    # Create the Qt console frontend.
    control = RichIPythonWidget()
    control.exit_requested.connect(app.quit)
    control.kernel_manager = km
    control.show()

    # Execute some code directly. Note where the output appears.
    kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)')

    # Execute some code through the frontend (once the event loop is
    # running). Again, note where the output appears.
    do_later(control.execute, '%who')

    guisupport.start_event_loop_qt4(app)
Exemplo n.º 5
0
 def start_kernel(self, **kwds):
     from IPython.kernel.inprocess.ipkernel import InProcessKernel
     self.kernel = InProcessKernel()
Exemplo n.º 6
0
 def start_kernel(self, **kwds):
     from IPython.kernel.inprocess.ipkernel import InProcessKernel
     self.kernel = InProcessKernel(parent=self, session=self.session)