Last active
January 13, 2016 06:26
-
-
Save rgbkrk/fa63ca210c4c0ddd499a to your computer and use it in GitHub Desktop.
Getting kernel info using enchannel-zmq-backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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); | |
Author
rgbkrk
commented
Jan 13, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment