1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- require(['jquery', '@jupyterlab/services'], function ($, services) {
- 'use strict';
- var startNewKernel = services.Kernel.startNew;
- var kernelOptions = {
- name: 'python',
- };
- // start a single kernel for the page
- /* eslint-disable no-console */
- startNewKernel(kernelOptions).then(function (kernel) {
- console.log('Kernel started:', kernel);
- kernel.requestKernelInfo().then(function (reply) {
- var content = reply.content;
- $('#kernel-info').text(content.banner);
- console.log('Kernel info:', content);
- });
- $('#run').click(function () {
- var code = $('#cell').val();
- console.log('Executing:', code);
- // clear output
- $('#output').text('');
- // Execute and handle replies on the kernel.
- var future = kernel.requestExecute({ code: code });
- // record each IOPub message
- future.onIOPub = function (msg) {
- console.log('Got IOPub:', msg);
- $('#output').append(
- $('<pre>').text('msg_type: ' + msg.header.msg_type)
- );
- $('#output').append(
- $('<pre>').text(JSON.stringify(msg.content))
- );
- };
- future.onReply = function (reply) {
- console.log('Got execute reply', reply);
- };
- future.done.then(function () {
- console.log('Future is fulfilled');
- $('#output').append($('<pre>').text('Done!'));
- });
- });
- });
- });
|