##// END OF EJS Templates
fix: JS kernel state should reflect killed state
Paul Ivanov -
Show More
@@ -1,117 +1,118 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2013 The IPython Development Team
2 // Copyright (C) 2013 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // Notebook
9 // Notebook
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13 "use strict";
14
14
15 var utils = IPython.utils;
15 var utils = IPython.utils;
16
16
17 var Session = function(notebook_name, notebook_path, notebook){
17 var Session = function(notebook_name, notebook_path, notebook){
18 this.kernel = null;
18 this.kernel = null;
19 this.id = null;
19 this.id = null;
20 this.name = notebook_name;
20 this.name = notebook_name;
21 this.path = notebook_path;
21 this.path = notebook_path;
22 this.notebook = notebook;
22 this.notebook = notebook;
23 this._baseProjectUrl = notebook.baseProjectUrl();
23 this._baseProjectUrl = notebook.baseProjectUrl();
24 };
24 };
25
25
26 Session.prototype.start = function(callback) {
26 Session.prototype.start = function(callback) {
27 var that = this;
27 var that = this;
28 var model = {
28 var model = {
29 notebook : {
29 notebook : {
30 name : this.name,
30 name : this.name,
31 path : this.path
31 path : this.path
32 }
32 }
33 };
33 };
34 var settings = {
34 var settings = {
35 processData : false,
35 processData : false,
36 cache : false,
36 cache : false,
37 type : "POST",
37 type : "POST",
38 data: JSON.stringify(model),
38 data: JSON.stringify(model),
39 dataType : "json",
39 dataType : "json",
40 success : function (data, status, xhr) {
40 success : function (data, status, xhr) {
41 that._handle_start_success(data);
41 that._handle_start_success(data);
42 if (callback) {
42 if (callback) {
43 callback(data, status, xhr);
43 callback(data, status, xhr);
44 }
44 }
45 },
45 },
46 };
46 };
47 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions');
47 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions');
48 $.ajax(url, settings);
48 $.ajax(url, settings);
49 };
49 };
50
50
51 Session.prototype.rename_notebook = function (name, path) {
51 Session.prototype.rename_notebook = function (name, path) {
52 this.name = name;
52 this.name = name;
53 this.path = path;
53 this.path = path;
54 var model = {
54 var model = {
55 notebook : {
55 notebook : {
56 name : this.name,
56 name : this.name,
57 path : this.path
57 path : this.path
58 }
58 }
59 };
59 };
60 var settings = {
60 var settings = {
61 processData : false,
61 processData : false,
62 cache : false,
62 cache : false,
63 type : "PATCH",
63 type : "PATCH",
64 data: JSON.stringify(model),
64 data: JSON.stringify(model),
65 dataType : "json",
65 dataType : "json",
66 };
66 };
67 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.id);
67 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.id);
68 $.ajax(url, settings);
68 $.ajax(url, settings);
69 };
69 };
70
70
71 Session.prototype.delete = function() {
71 Session.prototype.delete = function() {
72 var settings = {
72 var settings = {
73 processData : false,
73 processData : false,
74 cache : false,
74 cache : false,
75 type : "DELETE",
75 type : "DELETE",
76 dataType : "json",
76 dataType : "json",
77 };
77 };
78 this.kernel.running = false;
78 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.id);
79 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.id);
79 $.ajax(url, settings);
80 $.ajax(url, settings);
80 };
81 };
81
82
82 // Kernel related things
83 // Kernel related things
83 /**
84 /**
84 * Create the Kernel object associated with this Session.
85 * Create the Kernel object associated with this Session.
85 *
86 *
86 * @method _handle_start_success
87 * @method _handle_start_success
87 */
88 */
88 Session.prototype._handle_start_success = function (data, status, xhr) {
89 Session.prototype._handle_start_success = function (data, status, xhr) {
89 this.id = data.id;
90 this.id = data.id;
90 var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels");
91 var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels");
91 this.kernel = new IPython.Kernel(base_url);
92 this.kernel = new IPython.Kernel(base_url);
92 this.kernel._kernel_started(data.kernel);
93 this.kernel._kernel_started(data.kernel);
93 };
94 };
94
95
95 /**
96 /**
96 * Prompt the user to restart the IPython kernel.
97 * Prompt the user to restart the IPython kernel.
97 *
98 *
98 * @method restart_kernel
99 * @method restart_kernel
99 */
100 */
100 Session.prototype.restart_kernel = function () {
101 Session.prototype.restart_kernel = function () {
101 this.kernel.restart();
102 this.kernel.restart();
102 };
103 };
103
104
104 Session.prototype.interrupt_kernel = function() {
105 Session.prototype.interrupt_kernel = function() {
105 this.kernel.interrupt();
106 this.kernel.interrupt();
106 };
107 };
107
108
108
109
109 Session.prototype.kill_kernel = function() {
110 Session.prototype.kill_kernel = function() {
110 this.kernel.kill();
111 this.kernel.kill();
111 };
112 };
112
113
113 IPython.Session = Session;
114 IPython.Session = Session;
114
115
115 return IPython;
116 return IPython;
116
117
117 }(IPython));
118 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now