瀏覽代碼

WIP Shutdown kernel with widget

Frederic Collonval 6 年之前
父節點
當前提交
c7ad229049

+ 6 - 0
packages/console-extension/schema/tracker.json

@@ -35,6 +35,12 @@
       "type": "string",
       "enum": ["notebook", "terminal"],
       "default": "notebook"
+    },
+    "kernelShutdown": {
+      "title": "Shutdown kernel",
+      "description": "Whether to shutdown or not the kernel when closing a console.",
+      "type": "boolean",
+      "default": false
     }
   },
   "additionalProperties": false,

+ 6 - 0
packages/notebook-extension/schema/tracker.json

@@ -284,6 +284,12 @@
         "codeFolding": false
       }
     },
+    "kernelShutdown": {
+      "title": "Shutdown kernel",
+      "description": "Whether to shutdown or not the kernel when closing a notebook.",
+      "type": "boolean",
+      "default": false
+    },
     "markdownCellConfig": {
       "title": "Markdown Cell Configuration",
       "description": "The configuration for all markdown cells.",

+ 2 - 1
packages/notebook-extension/src/index.ts

@@ -618,7 +618,8 @@ function activateNotebookHandler(
     });
     factory.editorConfig = editorConfig = { code, markdown, raw };
     factory.notebookConfig = notebookConfig = {
-      scrollPastEnd: settings.get('scrollPastEnd').composite as boolean
+      scrollPastEnd: settings.get('scrollPastEnd').composite as boolean,
+      kernelShutdown: settings.get('kernelShutdown').composite as boolean
     };
   }
 

+ 6 - 1
packages/notebook/src/panel.ts

@@ -9,7 +9,7 @@ import { Message } from '@phosphor/messaging';
 
 import { ISignal, Signal } from '@phosphor/signaling';
 
-import { IClientSession } from '@jupyterlab/apputils';
+import { IClientSession, showErrorMessage } from '@jupyterlab/apputils';
 
 import { DocumentWidget } from '@jupyterlab/docregistry';
 
@@ -121,6 +121,11 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
    * Dispose of the resources used by the widget.
    */
   dispose(): void {
+    if (this.content.notebookConfig.kernelShutdown) {
+      this.context.session.shutdown().catch(reason => {
+        showErrorMessage('Kernel not shutdown', reason);
+      });
+    }
     this.content.dispose();
     super.dispose();
   }

+ 7 - 1
packages/notebook/src/widget.ts

@@ -730,12 +730,17 @@ export namespace StaticNotebook {
      * Enable scrolling past the last cell
      */
     scrollPastEnd: boolean;
+    /**
+     * Enable shutdown kernel when closing the notebook
+     */
+    kernelShutdown: boolean;
   }
   /**
    * Default configuration options for notebooks.
    */
   export const defaultNotebookConfig: INotebookConfig = {
-    scrollPastEnd: true
+    scrollPastEnd: true,
+    kernelShutdown: false
   };
 
   /**
@@ -942,6 +947,7 @@ export class Notebook extends StaticNotebook {
     if (this.isDisposed) {
       return;
     }
+    
     this._activeCell = null;
     super.dispose();
   }