| 451 | } |
| 452 | |
| 453 | public async shutdown(): Promise<void> { |
| 454 | try { |
| 455 | logger.info(`Shutdown requested ${getDisplayPath(this.uri)}`); |
| 456 | |
| 457 | // Cancel any pending starts |
| 458 | this.startCancellation.cancel(); |
| 459 | this.startCancellation.dispose(); |
| 460 | |
| 461 | // Get the current session if it exists |
| 462 | const session = this._jupyterSessionPromise |
| 463 | ? await this._jupyterSessionPromise.catch(() => undefined) |
| 464 | : undefined; |
| 465 | |
| 466 | if (session) { |
| 467 | logger.info('Shutting down kernel session'); |
| 468 | try { |
| 469 | await session.shutdown(); |
| 470 | } catch (ex) { |
| 471 | logger.warn(`Failed to shutdown kernel session ${getDisplayPath(this.uri)}`, ex); |
| 472 | // Continue with disposal even if shutdown fails |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | // Clean up the session references |
| 477 | this._session = undefined; |
| 478 | this._jupyterSessionPromise = undefined; |
| 479 | this._postInitializedOnStartPromise = undefined; |
| 480 | |
| 481 | logger.info(`Shutdown completed ${getDisplayPath(this.uri)}`); |
| 482 | } catch (ex) { |
| 483 | logger.error(`Failed to shutdown kernel ${getDisplayPath(this.uri)}`, ex); |
| 484 | throw ex; |
| 485 | } |
| 486 | } |
| 487 | protected async startJupyterSession(options: IDisplayOptions = new DisplayOptions(false)): Promise<IKernelSession> { |
| 488 | logger.info(`Starting Jupyter Session for ${getDisplayPath(this.uri)}, ${this.uri}`); |
| 489 | this._startedAtLeastOnce = true; |