Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
it('should take the options as an argument', () => {
manager.dispose();
manager = new KernelManager({
serverSettings: makeSettings(),
standby: 'never'
});
expect(manager instanceof KernelManager).to.equal(true);
});
});
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);
});
});
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);
});
});
it('should take the options as an argument', () => {
manager.dispose();
manager = new KernelManager({
serverSettings: makeSettings(),
standby: 'never'
});
expect(manager instanceof KernelManager).to.equal(true);
});
});
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);
});
});
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!');
}
public static async createNewKernel() {
const defaultKernelSpec = await KernelSpecAPI.getSpecs().then(
(res: KernelSpecAPI.ISpecModels) => res.default,
);
return await new KernelManager().startNew({ name: defaultKernelSpec });
}
SessionAPI.listRunning().then(allSessions => {
for (let i = 0; i < 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 }));
}
}
}
});
});