public
Last active

Embedded IPython kernel examples

  • Download Gist
embedded_qtconsole.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.frontend.qt.embedded_kernelmanager import QtEmbeddedKernelManager
from IPython.frontend.qt.kernelmanager import QtKernelManager
from IPython.lib import guisupport
 
 
def main():
app = guisupport.get_app_qt4()
 
km = QtEmbeddedKernelManager()
#km = QtKernelManager()
km.start_kernel()
km.start_channels()
 
def stop():
km.shutdown_kernel()
km.stop_channels()
app.exit()
 
control = RichIPythonWidget()
control.exit_requested.connect(stop)
control.kernel_manager = km
control.show()
 
guisupport.start_event_loop_qt4(app)
 
 
if __name__ == '__main__':
main()
embedded_terminal.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
from IPython.embedded.blockingkernelmanager import BlockingEmbeddedKernelManager
from IPython.zmq.blockingkernelmanager import BlockingKernelManager
 
# Note: ZMQTerminalInteractiveShell does not actually depend on ZMQ.
from IPython.frontend.terminal.console.interactiveshell import \
ZMQTerminalInteractiveShell
 
 
def main():
km = BlockingEmbeddedKernelManager()
#km = BlockingKernelManager()
km.start_kernel()
km.start_channels()
 
shell = ZMQTerminalInteractiveShell(kernel_manager=km)
shell.mainloop()
 
 
if __name__ == '__main__':
main()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.