From b587bb413df4334043d59deed1fd41fd6c8db744 Mon Sep 17 00:00:00 2001 From: Shawn Yama Date: Fri, 28 Jun 2024 09:52:42 -0400 Subject: [PATCH] fix: shutdown jupyter session on page unload (#4006) --- packages/client/hmi-client/src/services/jupyter.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/client/hmi-client/src/services/jupyter.ts b/packages/client/hmi-client/src/services/jupyter.ts index 41f4af880b..bc21e77c3e 100644 --- a/packages/client/hmi-client/src/services/jupyter.ts +++ b/packages/client/hmi-client/src/services/jupyter.ts @@ -280,6 +280,7 @@ export class KernelSessionManager { console.log('waiting...', this.jupyterSession?.session?.kernel); counter++; if (this.jupyterSession?.session?.kernel) { + window.addEventListener('beforeunload', this.shutdown.bind(this)); // bind(this) ensures that this instance of the class is used clearInterval(id); resolve(true); } @@ -318,6 +319,7 @@ export class KernelSessionManager { } shutdown() { + window.removeEventListener('beforeunload', this.shutdown.bind(this)); // bind(this) ensures that this instance of the class is used this.jupyterSession?.shutdown(); } }