()
| 365 | await this.disposingPromise; |
| 366 | } |
| 367 | public async restart(): Promise<void> { |
| 368 | try { |
| 369 | const resourceType = getResourceType(this.resourceUri); |
| 370 | logger.info(`Restart requested ${getDisplayPath(this.uri)}`); |
| 371 | await Promise.all( |
| 372 | Array.from(this.hooks.get('willRestart') || new Set<Hook>()).map((h) => h(this._jupyterSessionPromise)) |
| 373 | ); |
| 374 | this.startCancellation.cancel(); // Cancel any pending starts. |
| 375 | this.startCancellation.dispose(); |
| 376 | const stopWatch = new StopWatch(); |
| 377 | try { |
| 378 | // Check if the session was started already. |
| 379 | // Note, it could be empty if we were starting this and it got cancelled due to us |
| 380 | // cancelling the token earlier. |
| 381 | const session = this._jupyterSessionPromise |
| 382 | ? await this._jupyterSessionPromise.catch(() => undefined) |
| 383 | : undefined; |
| 384 | |
| 385 | if (session) { |
| 386 | // We already have a session, now try to restart that session instead of starting a whole new one. |
| 387 | // Just use the internal session. Pending cells should have been canceled by the caller |
| 388 | // Try to restart the current session if possible. |
| 389 | if (!this._restartPromise) { |
| 390 | // Just use the internal session. Pending cells should have been canceled by the caller |
| 391 | this._restartPromise = session.restart(); |
| 392 | this._restartPromise |
| 393 | // Done restarting, clear restart promise |
| 394 | .finally(() => (this._restartPromise = undefined)) |
| 395 | .catch(noop); |
| 396 | } |
| 397 | await this._restartPromise; |
| 398 | |
| 399 | // Re-create the cancel token as we cancelled this earlier in this method. |
| 400 | this.startCancellation = new CancellationTokenSource(); |
| 401 | } else { |
| 402 | // If the session died, then start a new session. |
| 403 | // Or possible the previously pending start was cancelled above. |
| 404 | await this.start(new DisplayOptions(false)); |
| 405 | } |
| 406 | sendKernelTelemetryEvent( |
| 407 | this.resourceUri, |
| 408 | Telemetry.NotebookRestart, |
| 409 | { duration: stopWatch.elapsedTime }, |
| 410 | { resourceType } |
| 411 | ); |
| 412 | } catch (ex) { |
| 413 | logger.error(`Restart failed ${getDisplayPath(this.uri)}`, ex); |
| 414 | this._ignoreJupyterSessionDisposedErrors = true; |
| 415 | // If restart fails, kill the associated session. |
| 416 | const session = this._session; |
| 417 | this._session = undefined; |
| 418 | this._jupyterSessionPromise = undefined; |
| 419 | this._postInitializedOnStartPromise = undefined; |
| 420 | // If we get a kernel promise failure, then restarting timed out. Just shutdown and restart the entire server. |
| 421 | // Note, this code might not be necessary, as such an error is thrown only when interrupting a kernel times out. |
| 422 | sendKernelTelemetryEvent( |
| 423 | this.resourceUri, |
| 424 | Telemetry.NotebookRestart, |
nothing calls this directly
no test coverage detected