(session: IKernelSession | undefined)
| 775 | } |
| 776 | |
| 777 | private async initializeAfterStart(session: IKernelSession | undefined) { |
| 778 | const nb = workspace.notebookDocuments.find((nb) => nb.uri.toString() === this.uri.toString()); |
| 779 | const tracker = getNotebookTelemetryTracker(nb); |
| 780 | const postInitialization = nb ? tracker?.postKernelStartup() : undefined; |
| 781 | try { |
| 782 | await Promise.all( |
| 783 | Array.from(this.hooks.get('didStart') || new Set<Hook>()).map((h) => |
| 784 | h(session, this.startCancellation.token).catch(noop) |
| 785 | ) |
| 786 | ); |
| 787 | logger.trace(`Started running kernel initialization for ${getDisplayPath(this.uri)}`); |
| 788 | if (!session) { |
| 789 | logger.trace('Not running kernel initialization'); |
| 790 | return; |
| 791 | } |
| 792 | if (!this.hookedSessionForEvents.has(session)) { |
| 793 | this.hookedSessionForEvents.add(session); |
| 794 | session.onDidKernelSocketChange((e) => this._onDidKernelSocketChange.fire(e)); |
| 795 | session.onDidDispose(() => { |
| 796 | logger.ci( |
| 797 | `Kernel got disposed as a result of session.onDisposed (1) ${getDisplayPath( |
| 798 | this.resourceUri || this.uri |
| 799 | )}` |
| 800 | ); |
| 801 | // Ignore when session is disposed as a result of failed restarts. |
| 802 | if (!this._ignoreJupyterSessionDisposedErrors) { |
| 803 | logger.info( |
| 804 | `Kernel got disposed as a result of session.onDisposed ${getDisplayPath( |
| 805 | this.resourceUri || this.uri |
| 806 | )} & _ignoreJupyterSessionDisposedErrors = false.` |
| 807 | ); |
| 808 | const isActiveSessionDead = this._session === session; |
| 809 | this._jupyterSessionPromise = undefined; |
| 810 | this._postInitializedOnStartPromise = undefined; |
| 811 | this._session = undefined; |
| 812 | |
| 813 | // If the active session died, then kernel is dead. |
| 814 | if (isActiveSessionDead) { |
| 815 | this.isKernelDead = true; |
| 816 | this._onStatusChanged.fire('dead'); |
| 817 | } |
| 818 | } |
| 819 | }); |
| 820 | const statusChangeHandler = (_: unknown, status: KernelMessage.Status) => |
| 821 | this._onStatusChanged.fire(status); |
| 822 | session.statusChanged.connect(statusChangeHandler); |
| 823 | this.disposables.push( |
| 824 | new Disposable(() => swallowExceptions(() => session.statusChanged.disconnect(statusChangeHandler))) |
| 825 | ); |
| 826 | } |
| 827 | |
| 828 | // So that we don't have problems with ipywidgets, always register the default ipywidgets comm target. |
| 829 | // Restart sessions and retries might make this hard to do correctly otherwise. |
| 830 | session.kernel?.registerCommTarget(Identifiers.DefaultCommTarget, noop); |
| 831 | |
| 832 | if (this.kernelConnectionMetadata.kind === 'connectToLiveRemoteKernel') { |
| 833 | // As users can have IPyWidgets at any point in time, we need to determine the version of ipywidgets |
| 834 | // This must happen early on as the state of the kernel needs to be synced with the Kernel in the webview (renderer) |
nothing calls this directly
no test coverage detected