index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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).then(function(s) {
  17. // Rename the session.
  18. session = s;
  19. return session.setPath('bar.ipynb');
  20. }).then(function() {
  21. console.log('Session renamed to', session.path);
  22. // Execute and handle replies on the kernel.
  23. var future = session.kernel.requestExecute({ code: 'a = 1' });
  24. future.onReply = function(reply) {
  25. console.log('Got execute reply', reply);
  26. };
  27. return future.done;
  28. }).then(function() {
  29. console.log('Future is fulfilled');
  30. // Shut down the session.
  31. return session.shutdown();
  32. }).then(function() {
  33. console.log('Session shut down');
  34. process.exit(0);
  35. }).catch(function(err) {
  36. console.error(err);
  37. process.exit(1);
  38. });