Skip to content

Instantly share code, notes, and snippets.

@rgbkrk
Last active January 13, 2016 06:26
Show Gist options
  • Save rgbkrk/fa63ca210c4c0ddd499a to your computer and use it in GitHub Desktop.
Save rgbkrk/fa63ca210c4c0ddd499a to your computer and use it in GitHub Desktop.
Getting kernel info using enchannel-zmq-backend
/*
* Retrieves kernel info, given a connection file
*
* node index.js /Users/rgbkrk/Library/Jupyter/runtime/kernel-24468.json
*
*/
const enchant = require('enchannel-zmq-backend');
const uuid = require('uuid');
const kernelArg = process.argv[2];
if (!kernelArg) {
console.error('Pass a kernel runtime file location as the first argument!');
process.exit(2);
}
const runtimeConfig = require(kernelArg);
const chan = enchant(runtimeConfig);
const msgID = uuid.v4();
const sessionID = uuid.v4();
var message = {
header: {
msg_id: msgID,
username: 'rgbkrk',
session: sessionID,
msg_type: 'kernel_info_request',
version: '5.0',
},
content: {},
};
const lang_info = chan.shell
.filter(msg => msg.parent_header.msg_id === msgID)
.pluck('content', 'language_info');
lang_info
.first()
.subscribe(info => {
console.log(`It's ${info.name}!`);
console.log(`Isn't ${info.name} ${info.version} a bit out of date?`);
// Clean up so we auto-exit
chan.shell.close();
chan.iopub.close();
chan.control.close();
chan.stdin.close();
});
// Send off the kernel_info_request
chan.shell.send(message);
@rgbkrk
Copy link
Author

rgbkrk commented Jan 13, 2016

$ node index.js /Users/rgbkrk/Library/Jupyter/runtime/kernel-24468.json
It's python!
Isn't python 2.7.11 a bit out of date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment