How to use the @jupyterlab/services.KernelManager function in @jupyterlab/services

To help you get started, we’ve selected a few @jupyterlab/services examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / services / examples / node / index.js View on Github external
var services = require('@jupyterlab/services');

// Start a new session.
var options = {
  path: 'foo.ipynb',
  type: 'notebook',
  name: 'foo.ipynb',
  kernel: {
    name: 'python'
  }
};

/* eslint-disable no-console */
console.log('Starting session...');
var kernelManager = new services.KernelManager();
var sessionManager = new services.SessionManager({ kernelManager });
var session;
sessionManager
  .startNew(options)
  .then(function(s) {
    // Rename the session.
    session = s;
    return session.setPath('bar.ipynb');
  })
  .then(function() {
    console.log('Session renamed to', session.path);
    // Execute and handle replies on the kernel.
    var future = session.kernel.requestExecute({ code: 'a = 1' });
    future.onReply = function(reply) {
      console.log('Got execute reply', reply);
    };
github jupyterlab / jupyterlab / tests / test-services / src / kernel / manager.spec.ts View on Github external
it('should take the options as an argument', () => {
        manager.dispose();
        manager = new KernelManager({
          serverSettings: makeSettings(),
          standby: 'never'
        });
        expect(manager instanceof KernelManager).to.equal(true);
      });
    });
github jupyterlab / jupyterlab / tests / test-services / src / kernel / manager.spec.ts View on Github external
it('should get the server settings', () => {
        manager.dispose();
        const serverSettings = makeSettings();
        const standby = 'never';
        const token = serverSettings.token;
        manager = new KernelManager({ serverSettings, standby });
        expect(manager.serverSettings.token).to.equal(token);
      });
    });
github jupyterlab / jupyterlab / tests / test-services / src / kernel / manager.spec.ts View on Github external
it('should test whether the manager is ready', async () => {
        manager.dispose();
        manager = new KernelManager({ standby: 'never' });
        expect(manager.isReady).to.equal(false);
        await manager.ready;
        expect(manager.isReady).to.equal(true);
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-services / src / kernel / manager.spec.ts View on Github external
it('should take the options as an argument', () => {
        manager.dispose();
        manager = new KernelManager({
          serverSettings: makeSettings(),
          standby: 'never'
        });
        expect(manager instanceof KernelManager).to.equal(true);
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-services / src / kernel / manager.spec.ts View on Github external
it('should get the server settings', () => {
        manager.dispose();
        const serverSettings = makeSettings();
        const standby = 'never';
        const token = serverSettings.token;
        manager = new KernelManager({ serverSettings, standby });
        expect(manager.serverSettings.token).to.equal(token);
      });
    });
github jupyterlab / jupyterlab / packages / services / examples / typescript-browser-with-output / src / index.ts View on Github external
async function main() {
  const code = [
    'from IPython.display import HTML',
    'HTML("<h1>Hello, world!</h1>")'
  ].join('\n');
  const model = new OutputAreaModel();
  const rendermime = new RenderMimeRegistry({ initialFactories });
  const outputArea = new OutputArea({ model, rendermime });

  const kernelManager = new KernelManager();
  const kernel = await kernelManager.startNew();
  outputArea.future = kernel.requestExecute({ code });
  document.getElementById('outputarea').appendChild(outputArea.node);
  await outputArea.future.done;
  console.log('Test complete!');
}
github kubeflow-kale / kale / labextension / src / lib / NotebookUtils.tsx View on Github external
public static async createNewKernel() {
    const defaultKernelSpec = await KernelSpecAPI.getSpecs().then(
      (res: KernelSpecAPI.ISpecModels) => res.default,
    );
    return await new KernelManager().startNew({ name: defaultKernelSpec });
  }
github JovianML / jovian-py / jovian / jovian-jupyter-lab-extension / src / NBKernel.ts View on Github external
SessionAPI.listRunning().then(allSessions =&gt; {
        for (let i = 0; i &lt; allSessions.length; i++) {
          let session = allSessions[i];
          if (session.type.toLowerCase() == "notebook") {
            let NBnameFromSession = session.name;
            if (
              NBnameFromSession.toLowerCase() ==
              this.currentNotebookName().toLowerCase()
            ) {
              let km = new KernelManager();
              resolve(km.connectTo({ model: session.kernel }));
            }
          }
        }
      });
    });