index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) 2014-2015, Jupyter Development Team.
  3. |
  4. | Distributed under the terms of the Modified BSD License.
  5. |----------------------------------------------------------------------------*/
  6. 'use strict';
  7. var services = require('@jupyterlab/services');
  8. // Start a new session.
  9. var options = {
  10. kernelName: 'python',
  11. path: 'foo.ipynb'
  12. };
  13. /* eslint-disable no-console */
  14. console.log('Starting session...');
  15. var session;
  16. services.Session.startNew(options)
  17. .then(function(s) {
  18. // Rename the session.
  19. session = s;
  20. return session.setPath('bar.ipynb');
  21. })
  22. .then(function() {
  23. console.log('Session renamed to', session.path);
  24. // Execute and handle replies on the kernel.
  25. var future = session.kernel.requestExecute({ code: 'a = 1' });
  26. future.onReply = function(reply) {
  27. console.log('Got execute reply', reply);
  28. };
  29. return future.done;
  30. })
  31. .then(function() {
  32. console.log('Future is fulfilled');
  33. // Shut down the session.
  34. return session.shutdown();
  35. })
  36. .then(function() {
  37. console.log('Session shut down');
  38. process.exit(0);
  39. })
  40. .catch(function(err) {
  41. console.error(err);
  42. process.exit(1);
  43. });